import axios from "../../../config/axios";
import type {
  GetPermissionsResponse,
  CreateAdminType,
  UpdateAdminType,
  GetAdminsResponse,
  Admin,
} from "../types/Types";

export const getAdmins = async (
  page: number = 1,
  limit: number = 10
): Promise<GetAdminsResponse> => {
  const { data } = await axios.get(`/admin/admins`, {
    params: { page, limit },
  });
  return data;
};

export const getPermissions = async (): Promise<GetPermissionsResponse> => {
  const { data } = await axios.get(`/admin/permissions`);
  return data;
};

export const createAdmin = async (admin: CreateAdminType) => {
  const { data } = await axios.post(`/admin/create`, admin);
  return data;
};

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

export const getAdminDetail = async (
  id: string
): Promise<{ status: number; success: boolean; results: { admin: Admin } }> => {
  const { data } = await axios.get(`/admin/${id}`);
  return data;
};

export const updateAdmin = async ({
  id,
  ...admin
}: { id: string } & UpdateAdminType) => {
  const { data } = await axios.put(`/admin/${id}/update`, admin);
  return data;
};
