FactoryBot.define do
  factory :medical_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 :non_native do
      contract do
        path = Rails.root.join("spec", "fixtures", "files", "contract.pdf")
        Rack::Test::UploadedFile.new(path, "application/pdf")
      end
    end

    factory :medical_release_with_contract_template do
      after(:build) do |medical_release, _|
        medical_release.contract_template = build(:medical_release_contract_template)
      end
    end

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

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