import axios from 'axios';
import { httpClient } from '@/services/http/client';
import { BaseApiResponse, LogoutResponse } from '@/types/api/api-general';

export class AuthApiService {
  async logout() {
    try {
      const logoutRes = await httpClient<LogoutResponse>(`/sso/logout`, {
        method: 'POST',
      });

      return logoutRes;
    } catch (error) {
      if (axios.isAxiosError<BaseApiResponse>(error)) {
        return error.response?.data;
      }

      return undefined;
    }
  }

  async refresh() {
    try {
      const refreshRes = await httpClient<BaseApiResponse>(`/sso/refresh`, {
        method: 'POST',
      });

      return refreshRes;
    } catch (error) {
      if (axios.isAxiosError<BaseApiResponse>(error)) {
        return error.response?.data;
      }
      return undefined;
    }
  }
}

export const AuthApi = new AuthApiService();
