<commit_before>'use strict'

class Factory
  build: (tag) ->
    switch tag.tag
      when 'fields'
        Builder = Field
      when 'picklistValues'
        Builder = PicklistValue
      else throw new Error 'unknown tag type'
    thing = new Builder()
    tag.getchildren().forEach (child) ->
      thing.set child.tag, child.text, child
    thing

factory = new Factory()

class Field
  constructor: ->
  set: (field, value, tag) ->
    switch field
    # required
      when 'fullName'
        @fullName = value
      when 'label'
        @label = value
      when 'type'
        @type = new Type value
      when 'length'
        @length = parseInt value, 10
      when 'trackHistory'
        @trackHistory = value is 'true'

    # common
      when 'externalId'
        @externalId = value is 'true'
      when 'required'
        @required = value is 'true'
      when 'unique'
        @unique = value is 'true'

    # others
      when 'caseSensitive'
        @caseSensitive = value is 'true'
      when 'defaultValue'
        @defaultValue = value
      when 'picklist'
        @picklist = new Picklist tag
      when 'visibleLines'
        @visibleLines = parseInt value, 10
      else throw new Error 'unknown field on field object'

class Type
  constructor: (@value) ->

class Picklist
  constructor: (tag) ->
    @sorted = tag.find('./sorted').text is 'true'
    plvs = @picklistValues = []
    tag.findall('./picklistValues').forEach (plv) ->
      plvs.push factory.build plv

class PicklistValue
  set: (field, value, tag) ->
    switch field
      when 'fullName'
        @fullName = value
      when 'default'
        @default = value is 'true'
      else throw new Error 'unknown field on picklist value object'

module.exports = factory<commit_msg>load complete object<commit_after>'use strict'

class Factory
  build: (tag) ->
    switch tag.tag
      when 'CustomObject'
        Builder = SObject
      when 'fields'
        Builder = Field
      when 'picklistValues'
        Builder = PicklistValue
      when 'actionOverrides'
        Builder = ActionOverride
      else throw new Error "unknown tag type #{tag.tag}"
    thing = new Builder()
    tag.getchildren().forEach (child) ->
      thing.set child.tag, child.text, child
    thing

factory = new Factory()

class SObject
  constructor: ->
    @fields = {}
    @actionOverrides = {}
  set: (field, value, tag) ->
    switch field
    # named children
      when 'fields'
        field = factory.build tag
        @fields[field.fullName] = field
      when 'actionOverrides'
        action = factory.build tag
        @actionOverrides[action.actionName] = action

    # smart members
      when 'sharingModel'
        @sharingModel = new SharingModel value
      when 'deploymentStatus'
        @deploymentStatus = new DeploymentStatus value
      when 'listViews', 'nameField', 'searchLayouts'
        # TODO: something
        ''

    # regular members
      when 'label'
        @label = value
      when 'pluralLabel'
        @pluralLabel = value
      when 'enableActivities'
        @enableActivities = value is 'true'
      when 'enableFeeds'
        @enableFeeds = value is 'true'
      when 'enableHistory'
        @enableHistory = value is 'true'
      when 'enableReports'
        @enableReports = value is 'true'
      else throw new Error "unknown field #{field} on custom object object"

class Field
  set: (field, value, tag) ->
    switch field
    # required
      when 'fullName'
        @fullName = value
      when 'label'
        @label = value
      when 'type'
        @type = new Type value
      when 'length'
        @length = parseInt value, 10
      when 'trackHistory'
        @trackHistory = value is 'true'

    # common
      when 'externalId'
        @externalId = value is 'true'
      when 'required'
        @required = value is 'true'
      when 'unique'
        @unique = value is 'true'

    # others
      when 'caseSensitive'
        @caseSensitive = value is 'true'
      when 'defaultValue'
        @defaultValue = value
      when 'picklist'
        @picklist = new Picklist tag
      when 'visibleLines'
        @visibleLines = parseInt value, 10
      else throw new Error "unknown field #{field} on field object"

class DeploymentStatus
  constructor: (@status) ->

class SharingModel
  constructor: (@model) ->

class Type
  constructor: (@value) ->

class Picklist
  constructor: (tag) ->
    @sorted = tag.find('./sorted').text is 'true'
    plvs = @picklistValues = []
    tag.findall('./picklistValues').forEach (plv) ->
      plvs.push factory.build plv

class PicklistValue
  set: (field, value, tag) ->
    switch field
      when 'fullName'
        @fullName = value
      when 'default'
        @default = value is 'true'
      else throw new Error "unknown field #{field} on picklist value object"

class ActionOverride
  set: (field, value, tag) ->
    switch field
      when 'actionName'
        @actionName = value
      when 'type'
        @type = value
      else throw new Error "unknown field #{field} on picklist value object"

module.exports = factory
{'fraction_non_alphanumeric': 0.09662877303018425, 'fraction_numerical': 0.0015680125441003528, 'mean_word_length': 2.24618320610687, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '1498749', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1444, 'n_words': 482}