# frozen_string_literal: true

module QualityApp
  module MrlChemicalsResultFactory
    def create_mrl_chemicals_result(opts = {})
      id = get_available_factory_record(:mrl_chemicals_results, opts)
      return id unless id.nil?

      opts[:mrl_result_id] ||= create_mrl_result
      opts[:chemical_id] ||= create_chemical

      default = {
        percentage_of_eu_level: Faker::Number.decimal,
        mrl_level_detected: Faker::Number.decimal,
        passed: false,
        active: true,
        created_at: '2010-01-01 12:00',
        updated_at: '2010-01-01 12:00'
      }
      DB[:mrl_chemicals_results].insert(default.merge(opts))
    end
  end
end
