FactoryBot.define do
  factory :misc_release do
    association :project

    person_first_name "Jane"
    person_last_name "Doe"

    photos [Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "person_photo.png"), "image/png")]

    trait :native do
      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 :minor do
      minor true
      guardian_first_name "Jamie"
      guardian_last_name "Doe"
      guardian_phone "123-555-1234"
    end

    trait :minor_with_guardian_photo do
      minor true
      guardian_first_name "Jamie"
      guardian_last_name "Doe"
      guardian_phone "123-555-1234"
      guardian_photo do
        path = Rails.root.join("spec", "fixtures", "files", "pratt.jpg")
        Rack::Test::UploadedFile.new(path, "image/jpeg")
      end
    end

    factory :misc_release_with_contract_template do
      after(:build) do |misc_release, _|
        misc_release.contract_template = build(:misc_release_contract_template)
      end
    end

    factory :misc_release_with_contract_template_and_photos do
      after(:build) do |misc_release, _|
        misc_release.contract_template = build(:misc_release_contract_template)
        path = Rails.root.join("spec", "fixtures", "files", "person_photo.png")
        misc_release.photos.attach Rack::Test::UploadedFile.new(path, "image/png")
      end
    end

    factory :misc_release_with_photo do
      after(:build) do |misc_release, _|
        path = Rails.root.join("spec", "fixtures", "files", "person_photo.png")
        misc_release.photos.attach Rack::Test::UploadedFile.new(path, "image/png")
      end
    end
  end
end
