class AcquiredMediaRelease < ApplicationRecord
  include Confirmable
  include Contractable
  include Exploitable
  include Notable
  include Releasable
  include Searchable
  include Taggable
  include Signable
  include Syncable
  include PersonName

  has_many :file_infos, as: :releasable, dependent: :destroy

  accepts_nested_attributes_for :file_infos

  composed_of :person_address,
              class_name: "Address",
              mapping: [ 
                %w(person_address_street1 street1), 
                %w(person_address_street2 street2), 
                %w(person_address_city city), 
                %w(person_address_state state), 
                %w(person_address_zip zip), 
                %w(person_address_country country) 
              ]

  validates :name, presence: true
  validates :person_email, email: true, allow_blank: true

  # These validations apply to releases created natively by the system (i.e. not imported from elsewhere)
  with_options on: :native do
    validates :signature, attached: true
  end

  # These validations apply to releases imported to the system from an outside source
  with_options on: :non_native do
    validates :contract, attached: true
  end

  searchable_on %i[
    name
    person_address_street1 person_address_street2 person_address_city person_address_state person_address_zip person_address_country
  ]

  # CATEGORIES = ["Artwork", "Film Footage", "Video Footage", "Still Photograph"].freeze
  CATEGORIES = ["Film Footage", "Video Footage", "Still Photograph"].freeze

  def minor?
    false
  end

  def contact_person
    @contact_person ||= Contact.new(person_name, person_address, person_email, person_phone)
  end

  def uses_edl?
    true
  end
end
