import axios from "@/config/axios";
import type {
  SellersResponse,
  WholesaleRequestsResponse,
  WithdrawalRequestsResponse,
  CreateAnnouncementSeller,
  NotificationsResponse,
  CreateAnnouncementSpecificSeller,
  GetRequestCreateProductResponse,
  CreateCategoryLearning,
  GetLearningCategoryResponse,
  GetLearningResponse,
  CreateLearningType,
  UpdateContractType,
  ChangeStatusDocumentType,
} from "../types/Types";

export const getSellers = async (
  page: number = 1,
  search: string
): Promise<SellersResponse> => {
  const { data } = await axios.get(`/admin/sellers?page=${page}&q=${search}`);
  return data;
};

export const toggleSellerStatus = async (sellerId: string) => {
  const { data } = await axios.patch(
    `/admin/sellers/approve-register/${sellerId}`
  );
  return data;
};

export const approveContract = async (sellerId: string) => {
  const { data } = await axios.patch(
    `/admin/sellers/approve-contract/${sellerId}`
  );
  return data;
};

export const getWholesaleRequests = async (
  page: number = 1
): Promise<WholesaleRequestsResponse> => {
  const { data } = await axios.get(
    `/admin/sellers/wholesale-requests?page=${page}`
  );
  return data;
};

export const approveWholesaleRequest = async (id: string) => {
  const { data } = await axios.patch(`/admin/sellers/wholesale-requests/${id}`);
  return data;
};

export const getWithdrawalRequests = async (
  page: number = 1
): Promise<WithdrawalRequestsResponse> => {
  const { data } = await axios.get(
    `/admin/financial/withdrawal/requests?page=${page}`
  );
  return data;
};

export const getAnnouncementSeller = async (
  page: number = 1
): Promise<NotificationsResponse> => {
  const { data } = await axios.get(
    `/admin/notification/allSeller?page=${page}`
  );
  return data;
};

export const createAnnouncementSeller = async (
  params: CreateAnnouncementSeller
) => {
  const { data } = await axios.post(`/admin/notification/allSeller`, params);
  return data;
};

export const createAnnouncementToSpecificSellers = async (
  params: CreateAnnouncementSpecificSeller
) => {
  const { data } = await axios.post(
    `/admin/notification/specific-sellers`,
    params
  );
  return data;
};

export const getRequestCreateProduct = async (
  page: number = 1
): Promise<GetRequestCreateProductResponse> => {
  const { data } = await axios.get(
    `/admin/products/requests/add-by-admin?page=${page}`
  );
  return data;
};

export const getLearningCategory = async (): Promise<
  GetLearningCategoryResponse
> => {
  const { data } = await axios.get(`/learning/category`);
  return data;
};

export const createLearningCategory = async (
  params: CreateCategoryLearning
) => {
  const { data } = await axios.post(`/admin/learning/category`, params);
  return data;
};

export const updateLearningCategory = async (
  id: string,
  params: CreateCategoryLearning
) => {
  const { data } = await axios.patch(
    `/admin/learning/category/${id}/update`,
    params
  );
  return data;
};

export const getLearning = async (): Promise<GetLearningResponse> => {
  const { data } = await axios.get(`/learning`);
  return data;
};

export const createLearning = async (params: CreateLearningType) => {
  const { data } = await axios.post(`/admin/learning`, params);
  return data;
};

export const updateLearning = async (
  id: string,
  params: CreateLearningType
) => {
  const { data } = await axios.patch(`/admin/learning/${id}/update`, params);
  return data;
};

export const getLearningById = async (id: string) => {
  const { data } = await axios.get(`/learning/${id}`);
  return data;
};

export const deleteLearning = async (id: string) => {
  const { data } = await axios.delete(`/admin/learning/${id}`);
  return data;
};

export const getContentContract = async () => {
  const { data } = await axios.get(`/admin/settings/contract`);
  return data;
};

export const updateContract = async (params: UpdateContractType) => {
  const { data } = await axios.patch(
    `/admin/settings/contract/${params.id}/update`,
    params
  );
  return data;
};

export const changeStatusDocument = async (
  sellerId: string,
  params: ChangeStatusDocumentType
) => {
  const { data } = await axios.patch(
    `/admin/sellers/document/${sellerId}`,
    params
  );
  return data;
};
