FactoryBot.define do
  factory :project do
    association :account

    client_name "My Client"
    description "This is the video project description."
    details "These are the details of the video project. "
    name "My Video Project"
    producer_address "123 Corporate Lane, New York, NY 10001"
    producer_name "Production Company, LLC"

    # Enable all release category sections by default
    after(:build) do |project, _|
      project.settings(:features).attributes = {
        acquired_media_release: true,
        appearance_release: true,
        location_release: true,
        material_release: true,
        music_release: true,
        talent_release: true,
        video_analysis: true,
      }
    end

    # Allow team members to be set for a given project
    after(:build) do |project, evaluator|
      Array.wrap(evaluator.members).each do |member|
        next if member.account_manager?(project.account)
        project.project_memberships.build(user: member)
      end
    end

    transient do
      members { [] }
    end

    trait :sample do
      name "My Sample Video Project"
      sample true
    end

    trait :discovery_client do
      predefined_client_name "discovery"
    end

    trait :nat_geo_client do
      predefined_client_name "nat_geo"
    end

    factory :project_with_contract_template do
      after(:build) do |project, _|
        project.contract_templates << build(:contract_template, project: nil)
      end
    end

    factory :project_with_directories do
      after(:build) do |project, _|
        project.directories << build(:directory, project: nil, name: "Shared")
        project.directories << build(:directory, :for_manager, project: nil, name: "Financial Documents")
        project.directories << build(:directory, :for_account_manager, project: nil, name: "Salaries")
      end
    end
  end
end
