import {
  Area,
  CheckoutDetailResponse,
  ConfirmOrderResponse,
} from "../services/product/type";
import { BaseApi } from "./baseApi";

class ProductApi extends BaseApi {
  constructor() {
    super("/api");
  }

  async loadArea({ isCountry = "-1", isPopular = "-1" }) {
    return this.productPost("/list_area", {
      isCountry,
      isPopular,
    });
  }

  async loadPackage({ areaId, dataType = "-1" }) {
    return this.productPost("/list_packg", { areaId, dataType });
  }

  async checkout({ packgId, quantity }) {
    return this.productPost<CheckoutDetailResponse>("/place_order", {
      packgId,
      quantity,
    });
  }

  async confirmOrder({
    surName,
    lastName,
    email,
    phoneNumber,
    paymentChannelId,
    packgId,
    quantity,
  }) {
    return this.productPost<ConfirmOrderResponse>("/confirm_order", {
      surName,
      lastName,
      email,
      phoneNumber,
      paymentChannelId,
      packgId,
      quantity,
    });
  }

  async loadPaymentChannel() {
    return this.productPost("/list_payment_channel", {});
  }

  async getOrderHistory({ searchOrder, fromDate, toDate, status }) {
    return this.productPost("/list_order", { searchOrder, fromDate, toDate, status });
  }

  async getOrderDetail({ orderId }) {
    return this.productPost("/get_order_detail", { orderId });
  }

  async checkDataUsage({ iccid }) {
    return this.productPost("/check_data_usage", { iccid });
  }

  async loadRelatedArea({ areaId }) {
    return this.productPost("/related_area", { areaId });
  }
}

export const productApi = new ProductApi();
