module Support
  module Services
    class OwsPromoPlayer
      include HTTParty

      base_uri DOMAINS[:ows_promo_player]

      class << self
        def get_player_by_code(code)
          response = get("/player/code/#{code}")
          JSON.parse(response.body)
        end

        def create_player(
          vendor_id,
          product_id,
          expiration_mode: "none",
          skin: "light"
        )
          url = "/product/#{product_id}/player"
          body = { "expiration_mode" => expiration_mode,
                   "skin" => skin,
                   "vendor_id" => vendor_id }.to_json
          headers = { "Content-Type" => "application/json" }
          post(url, body: body, headers: headers)
        end

        # rubocop:disable Metrics/ParameterLists
        def update_player(
          vendor_id,
          product_id,
          player_id,
          expiration_mode: "none",
          skin: "light",
          active: true
        )
          url = "/product/#{product_id}/player/#{player_id}"
          body = { "expiration_mode" => expiration_mode,
                   "skin" => skin,
                   "vendor_id" => vendor_id,
                   "active" => active }.to_json
          headers = { "Content-Type" => "application/json" }
          put(url, body: body, headers: headers)
        end
        # rubocop:enable Metrics/ParameterLists

        def get_players(product_id)
          url = "/product/#{product_id}/players"
          get(url)
        end

        def delete_players(product_id)
          url = "/admin/product/#{product_id}/players"
          delete(url)
        end
      end
    end
  end
end
