import { useDataSource } from "@erp/core/hooks";
import { ILoginRequestDTO, ILoginResponseDTO } from "../../common";

export interface IAuthService {
  login: (credentials: ILoginRequestDTO) => Promise<ILoginResponseDTO>;
}

export const createAuthService = (): IAuthService => {
  return {
    login: async (credentials: ILoginRequestDTO) => {
      const dataSource = useDataSource();
      const data = await dataSource.custom<ILoginResponseDTO>({
        path: "login",
        method: "post",
        data: credentials,
      });

      return data;
    },
  };
};
