module DataTests
  module AccountingRun
    class VendorContract
      attr_reader :oms_type, :digital_split, :oms_fee_percentage

      def initialize(vendor_id)
        contract = get_vendor_contract(vendor_id)
        @oms_type = get_oms_type(contract["oms_type"])
        @digital_split = contract["digital_split"].to_f
        @oms_fee_percentage = contract["oms_fee_percentage"].to_f
      end

      private

      def get_vendor_contract(id)
        puts "  vendor_id: #{id}"
        query_string = "SELECT * FROM vendor_contract WHERE vendor_id = #{id} AND cont_end > \"#{Date.today.to_s}\""
        query = DbQuery.new(query_string)
        query.expect_results
        query.expect_one_result
        query.results.first
      end

      def get_oms_type(type)
        case type
        when "none"
          oms_type = :none
        when "both"
          oms_type = :both
        when "label"
          oms_type = :label
        when "orchard"
          oms_type = :orchard
        else
          fail "unknown oms_type: #{type}"
        end
        puts "    vendor oms_type: #{type}"
        oms_type
      end
    end
  end
end
