# typed: false
FactoryBot.define do
  factory :domain_post_file, class: "Domain::PostFile" do
    state { "pending" }
    association :post, factory: :domain_post_fa_post

    trait :has_url do
      url_str { "https://example.com/image.jpg" }
    end

    trait :has_file do
      state { "ok" }
      url_str { "https://example.com/image.jpg" }
      last_status_code { 200 }
      before(:create) do |post_file|
        post_file.log_entry =
          create(
            :http_log_entry,
            url_str: post_file.url_str,
            status_code: post_file.last_status_code,
          )
      end
    end

    trait :terminal_error do
      state { "terminal_error" }
      url_str { "https://example.com/image.jpg" }
      last_status_code { 404 }
      before(:create) do |post_file|
        post_file.log_entry =
          create(
            :http_log_entry,
            url_str: post_file.url_str,
            status_code: post_file.last_status_code,
          )
      end
    end

    trait :retryable_error do
      state { "retryable_error" }
      url_str { "https://example.com/image.jpg" }
      last_status_code { 500 }
      before(:create) do |post_file|
        post_file.log_entry =
          create(
            :http_log_entry,
            url_str: post_file.url_str,
            status_code: post_file.last_status_code,
          )
      end
    end
  end

  trait :image_file do
    url_str { "https://example.com/image.jpg" }
    log_entry { create(:http_log_entry, :image_entry) }
  end

  trait :text_file do
    log_entry { create(:http_log_entry, :text_entry) }
    url_str { log_entry.uri_str }
  end

  trait :gif_file do
    url_str { "https://example.com/image.gif" }
    log_entry { create(:http_log_entry, :gif_entry) }
  end

  trait :webm_file do
    url_str { "https://example.com/image.webm" }
    log_entry { create(:http_log_entry, :webm_entry) }
  end
end

FactoryBot.define do
  factory :domain_post_file_inkbunny_post_file,
          class: "Domain::PostFile::InkbunnyPostFile",
          parent: :domain_post_file do
    association :post, factory: :domain_post_fa_post
    sequence(:ib_id) { |n| 12_345 + n }
    sequence(:file_name) { |n| "image#{n}.jpg" }
    sequence(:url_str) { |n| "https://example.com/image#{n}.jpg" }
    file_order { 1 }
    md5_initial { "d41d8cd98f00b204e9800998ecf8427e" }
    md5_full { "d41d8cd98f00b204e9800998ecf8427e" }
  end
end
