FactoryBot.define do
  factory :acquired_media_release do
    association :project

    name "Test Acquired Media Release"

    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

    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
