<commit_before>//
//  CoreDataContext.swift
//  SwiftGenKit
//
//  Created by <NAME> on 7/18/18.
//  Copyright © 2018 AliSoftware. All rights reserved.
//

import Foundation

extension CoreData.Parser {
  public func stencilContext() -> [String: Any] {
    return [
      "models": models.map(map)
    ]
  }

  private func map(_ model: CoreData.Model) -> [String: Any] {
    return [
      "configurations": model.configurations.mapValues { $0.map(map) },
      "entities": model.entities.mapValues(map),
      "fetchRequests": model.fetchRequests.map(map),
      "fetchRequestsByEntityName": model.fetchRequestsByEntityName.mapValues { $0.map(map) }
    ]
  }

  private func map(_ entity: CoreData.Entity) -> [String: Any] {
    return [
      "name": entity.name,
      "className": entity.className,
      "isAbstract": entity.isAbstract,
      "userInfo": entity.userInfo,
      "superentity": entity.superentity as Any,
      "attributes": entity.attributes.map(map),
      "relationships": entity.relationships.map(map)
    ]
  }

  private func map(_ attribute: CoreData.Attribute) -> [String: Any] {
    return [
      "name": attribute.name,
      "isIndexed": attribute.isIndexed,
      "isOptional": attribute.isOptional,
      "isTransient": attribute.isTransient,
      "usesScalarValueType": attribute.usesScalarValueType,
      "type": attribute.type.rawValue,
      "customClassName": attribute.customClassName as Any,
      "typeName": attribute.typeName,
      "userInfo": attribute.userInfo
    ]
  }

  private func map(_ relationship: CoreData.Relationship) -> [String: Any] {
    return [
      "name": relationship.name,
      "isIndexed": relationship.isIndexed,
      "isOptional": relationship.isOptional,
      "isTransient": relationship.isTransient,
      "isToMany": relationship.isToMany,
      "isOrdered": relationship.isOrdered,
      "destinationEntity": relationship.destinationEntity,
      "inverseRelationship": relationship.inverseRelationship.map {
        [
          "name": $0.name,
          "entityName": $0.entityName
        ]
      } as Any,
      "userInfo": relationship.userInfo
    ]<commit_msg>Provide default values for optional properties instead.<commit_after>//
//  CoreDataContext.swift
//  SwiftGenKit
//
//  Created by <NAME> on 7/18/18.
//  Copyright © 2018 AliSoftware. All rights reserved.
//

import Foundation

extension CoreData.Parser {
  public func stencilContext() -> [String: Any] {
    return [
      "models": models.map(map)
    ]
  }

  private func map(_ model: CoreData.Model) -> [String: Any] {
    return [
      "configurations": model.configurations,
      "entities": model.entities.mapValues(map),
      "fetchRequests": model.fetchRequests.map(map),
      "fetchRequestsByEntityName": model.fetchRequestsByEntityName.mapValues { $0.map(map) }
    ]
  }

  private func map(_ entity: CoreData.Entity) -> [String: Any] {
    return [
      "name": entity.name,
      "className": entity.className,
      "isAbstract": entity.isAbstract,
      "userInfo": entity.userInfo,
      "superentity": entity.superentity ?? "",
      "attributes": entity.attributes.map(map),
      "relationships": entity.relationships.map(map)
    ]
  }

  private func map(_ attribute: CoreData.Attribute) -> [String: Any] {
    return [
      "name": attribute.name,
      "isIndexed": attribute.isIndexed,
      "isOptional": attribute.isOptional,
      "isTransient": attribute.isTransient,
      "usesScalarValueType": attribute.usesScalarValueType,
      "type": attribute.type.rawValue,
      "customClassName": attribute.customClassName ?? "",
      "typeName": attribute.typeName,
      "userInfo": attribute.userInfo
    ]
  }

  private func map(_ relationship: CoreData.Relationship) -> [String: Any] {
    return [
      "name": relationship.name,
      "isIndexed": relationship.isIndexed,
      "isOptional": relationship.isOptional,
      "isTransient": relationship.isTransient,
      "isToMany": relationship.isToMany,
      "isOrdered": relationship.isOrdered,
      "destinationEntity": relationship.destinationEntity,
      "inverseRelationship": relationship.inverseRelationship.map {
        [
          "name": $0.name,
          "entityName": $0.entityName
        ]
      } as Any,
      "userInfo": relationship.userInfo
    ]
{'fraction_non_alphanumeric': 0.13027352804821513, 'fraction_numerical': 0.005795085767269356, 'mean_word_length': 3.066918001885014, 'pattern_counts': {'":': 64, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7384675', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1271, 'n_words': 259}