FactoryBot.define do
  factory :appearance_release do
    association :project

    person_first_name "Jane"
    person_last_name "Doe"

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

    trait :native do
      person_address "100 Test Lane, New York, NY 10001"
      person_phone "123-555-6789"

      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 "Jamie"
      guardian_last_name "Doe"
      guardian_address "100 Test Lane, New York, 10001"
      guardian_phone "123-555-1234"
      guardian_email "guardian@galaxy.all"
    end

    trait :minor_with_guardian_photo do
      minor true
      guardian_first_name "Jamie"
      guardian_last_name "Doe"
      guardian_address "100 Test Lane, New York, 10001"
      guardian_phone "123-555-1234"
      guardian_email "guardian@galaxy.all"
      guardian_photo do
        path = Rails.root.join("spec", "fixtures", "files", "pratt.jpg")
        Rack::Test::UploadedFile.new(path, "image/jpeg")
      end
    end

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

    trait :with_person_photo_only do
    end

    factory :appearance_release_with_contract_template do
      after(:build) do |appearance_release, _|
        appearance_release.contract_template = build(:appearance_release_contract_template)
      end
    end

    factory :appearance_release_import do
      person_photo nil

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

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

  end
end
