FactoryBot.define do
  factory :acquired_media_release do
    association :project

    name "Test Acquired Media Release"

    trait :with_address do
      person_address_street1 "St1"
      person_address_street2 "St2"
      person_address_city "City"
      person_address_state "State"
      person_address_zip "123"
      person_address_country "US"
    end

    trait :with_owner_info do
      person_first_name "Jane"
      person_last_name "Doe"
      person_phone "100-555-1001"
      person_email "owner@email.com"
    end

    trait :native do
      signature do
        path = Rails.root.join("spec", "fixtures", "files", "signature.png")
        Rack::Test::UploadedFile.new(path, "image/png")
      end
    end

    trait :non_native do
      contract do
        path = Rails.root.join("spec", "fixtures", "files", "contract.pdf")
        Rack::Test::UploadedFile.new(path, "application/pdf")
      end
    end

    trait :minor do
      minor true
      guardian_first_name "Guardian1"
      guardian_last_name "First"
      guardian_2_first_name "Guardian2"
      guardian_2_last_name "Second"
      guardian_phone "1111"
      guardian_2_phone "2222"
    end

    factory :acquired_media_release_with_contract_template do
      after(:build) do |acquired_media_release, _|
        acquired_media_release.contract_template = build(:acquired_media_release_contract_template)
      end
    end

    factory :acquired_media_release_with_file_infos do
      transient do
        file_infos_count { 3 }
      end

      after(:create) do |acquired_media_release, evaluator|
        create_list(:file_info, evaluator.file_infos_count, releasable: acquired_media_release)
      end
    end
  end
end
