FactoryBot.define do
  factory :music_release do
    association :project
    name "OST Test"
    person_first_name "John"
    person_last_name "Doe"

    after(:build) do |music_release, _|
      music_release.composers << build(:composer, music_release: music_release) if music_release.composers.empty?
      music_release.publishers << build(:publisher, music_release: music_release) if music_release.publishers.empty?
    end

    factory :music_release_with_contract_template do
      after(:build) do |music_release, _|
        music_release.contract_template = build(:contract_template)
      end
    end

    factory :music_release_with_file_infos do
      transient do
        file_infos_count { 3 }
      end

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