import { apiRequest } from "@/services/apiClient";
import type {
  AuthTokens,
  LoginCredentials,
  RegisterPayload,
  User,
} from "@/types";

export const authService = {
  async login(credentials: LoginCredentials) {
    return apiRequest<{ user: User; token: AuthTokens }>("/auth/login", {
      method: "POST",
      body: credentials,
    });
  },

  async register(payload: RegisterPayload) {
    return apiRequest<{ user: User; token: AuthTokens }>("/auth/register", {
      method: "POST",
      body: payload,
    });
  },

  async me(token: string) {
    return apiRequest<User>("/auth/me", { token });
  },

  async logout(token: string) {
    return apiRequest<null>("/auth/logout", {
      method: "POST",
      token,
    });
  },

  async forgotPassword(email: string) {
    return apiRequest<null>("/auth/forgot-password", {
      method: "POST",
      body: { email },
    });
  },

  async resetPassword(payload: {
    email: string;
    token: string;
    password: string;
    password_confirmation: string;
  }) {
    return apiRequest<null>("/auth/reset-password", {
      method: "POST",
      body: payload,
    });
  },
};

export type AuthService = typeof authService;
