import axios from "../../../config/axios";
import {
  CreateGroupIconType,
  CreateIconType,
  GroupIconsResponse,
  IconsResponse,
  ReportsResponse,
  ShopsResponse,
  ShopResponse,
  ShopSmsCountResponse,
  AddAdminShopType,
  SystemRolesResponse,
  ShopAdminsResponse,
  UpdateShopType,
} from "../types/Types";

export const getIcons = async (): Promise<IconsResponse> => {
  const { data } = await axios.get("/admin/dkala/icons");
  return data;
};

export const createGroupIcon = async (params: CreateGroupIconType) => {
  const { data } = await axios.post("/admin/dkala/icons/groups", params);
  return data;
};

export const getGroupIcons = async (): Promise<GroupIconsResponse> => {
  const { data } = await axios.get("/admin/dkala/icons/groups");
  return data;
};

export const deleteGroupIcon = async (id: string) => {
  const { data } = await axios.delete(`/admin/dkala/icons/groups/${id}`);
  return data;
};

export const createIcon = async (params: CreateIconType) => {
  const { data } = await axios.post("/admin/dkala/icons", params);
  return data;
};

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

export const getReports = async (): Promise<ReportsResponse> => {
  const { data } = await axios.get("/admin/dkala/contacts");
  return data;
};

export const getShops = async (
  page: number = 1,
  limit: number = 10
): Promise<ShopsResponse> => {
  const { data } = await axios.get(
    `/admin/dkala/shops?page=${page}&limit=${limit}`
  );
  return data;
};

export const getShopAdmins = async (
  shopId: string
): Promise<ShopAdminsResponse> => {
  const { data } = await axios.get(
    `/admin/dkala/shops/${shopId}/admins`
  );
  return data;
};

export const getShopSmsCount = async (): Promise<
  ShopSmsCountResponse
> => {
  const { data } = await axios.get(`/admin/dkala/shops/sms-count`);
  return data;
};

export const deleteShopAdmin = async (
  shopId: string,
  adminId: string
) => {
  const { data } = await axios.delete(
    `/admin/dkala/shops/${shopId}/admins/${adminId}`
  );
  return data;
};

export const addAdminShop = async (params: AddAdminShopType) => {
  const { data } = await axios.post(
    `/admin/dkala/shops/${params.shopId}/admins`,
    params
  );
  return data;
};

export const getSystemRoles = async (): Promise<SystemRolesResponse> => {
  const { data } = await axios.get(`/admin/dkala/system-roles`);
  return data;
};

export const updateShop = async (
  id: string,
  params: UpdateShopType
) => {
  const { data } = await axios.patch(`/admin/dkala/shops/${id}`, params);
  return data;
};

export const getShop = async (
  id: string
): Promise<ShopResponse> => {
  const { data } = await axios.get(`/admin/dkala/shops/${id}`);
  return data;
};

export const hardDeleteShop = async (id: string) => {
  const { data } = await axios.delete(
    `/admin/dkala/shops/${id}/hard-delete`
  );
  return data;
};
