require 'planter'
# extensions to the NMO modeling layer for use in build

Sequel::Plugins::Planter::GENERATE_PK = true

if conf.log.respond_to?(:info)
  TRACER_LOG = conf.log
  require 'planter/trace'
  # Sequel::Plugins::Planter::Trace.log = conf.log
end

class Sequel::Model
  include Yell::Loggable
  plugin :planter
end

value_fields = Hash[
  :neuron_region1 => :region1,
  :neuron_region2 => :region2,
  :neuron_region3 => :region3,
  :species => :species,
  :animal_strain => :strain_name,
  :age_classification => :age_class,
  :archive => :archive_name,
  :original_format => :original_format,
  :experimentcondition => :expercond,
  :reconstruction => :reconstruction_software,
  :slicing_direction => :slicing_direction,
  :slicing_thickness => :slice_thickness,
  :objective_type => :objective_type,
  :protocol_design => :protocol,
  :staining_method => :stain,
  :magnification => :magnification,
  :neuron_class3 => :class3,
  :neuron_class2 => :class2,
  :neuron_class1 => :class1,
  :code_intermed => :description,
  :pmid => :pmid,
  :neuron => :neuron_name
]
value_fields.each do |k,v|
  eval(k.to_s.camelize).class_eval do
    eigen.define_method :parse do |str|
      new(v => str)
    end
  end
end

neuron_extra_tables = %w[ 
  measurements
  measurementsAP
  measurementsAPA
  measurementsAPB
  measurementsAX
  measurementsBS
  measurementsBSA
  Tissue_shrinkage
  file_model
  deposition
  celltype_table
  neuron_auxdata
]
neuron_extra_tables.each do |t|
  t.camelize.constantize.class_eval do
    generate_pk -> do
      Neuron.first(neuron_name: @seeds[:neuron_name] || @seeds[:Neuron_name]).pk
    end
  end
end

