import httpClient from '@/shared/config/api/httpClient';
import { API_URLS } from '@/shared/config/api/URLs';
import { AxiosResponse } from 'axios';
import {
  FavouriteProduct,
  ProductDetail,
  ProductList,
  SearchData,
} from './type';

export const product_api = {
  async list(params: {
    page: number;
    page_size: number;
    product_type_id?: number;
    category_id?: number;
  }): Promise<AxiosResponse<ProductList>> {
    const res = await httpClient.get(`${API_URLS.Product}list/`, { params });
    return res;
  },

  async listGetCategoryId({
    params,
    category_id,
  }: {
    params: {
      page: number;
      page_size: number;
    };
    category_id: string;
  }): Promise<AxiosResponse<ProductList>> {
    const res = await httpClient.get(
      `${API_URLS.Product}${category_id}/list/`,
      { params },
    );
    return res;
  },

  async detail(id: string): Promise<AxiosResponse<ProductDetail>> {
    const res = await httpClient.get(`${API_URLS.Product}${id}`);
    return res;
  },

  async search(params: {
    search?: string;
    page?: number;
    page_size?: number;
  }): Promise<AxiosResponse<SearchData>> {
    const res = await httpClient.get(`${API_URLS.Search_Product}`, { params });
    return res;
  },

  async favourite(product_id: string) {
    const res = await httpClient.get(API_URLS.Favourite(product_id));
    return res;
  },

  async favouuriteProduct(): Promise<AxiosResponse<FavouriteProduct>> {
    const res = await httpClient.get(API_URLS.FavouriteProduct);
    return res;
  },
};
