import { baseRequestClient, requestClient } from '#/api/request';

export namespace AuthApi {
  /** 登录接口参数 */
  export interface LoginParams {
    username: string;
    password: string;
  }

  /** 登录接口返回值 */
  export interface LoginResult {
    accessToken?: string;
    [key: string]: any;
  }

  export interface RefreshTokenResult {
    data: string;
    status: number;
  }
}

/**
 * 管理员登录
 * POST /api/admin/login
 */
export async function loginApi(data: AuthApi.LoginParams) {
  return requestClient.post<AuthApi.LoginResult>('/api/admin/login', data);
}

/**
 * 获取当前管理员信息
 * GET /api/admin/login/info
 */
export async function getAdminInfoApi() {
  return requestClient.get<any>('/api/admin/login/info');
}

/**
 * 退出登录
 * POST /api/admin/login/logout
 */
export async function logoutApi() {
  return baseRequestClient.post('/api/admin/login/logout');
}

/**
 * 刷新accessToken（如果后端支持）
 */
export async function refreshTokenApi() {
  return baseRequestClient.post<AuthApi.RefreshTokenResult>('/auth/refresh');
}

/**
 * 获取用户权限码
 */
export async function getAccessCodesApi() {
  return requestClient.get<string[]>('/auth/codes');
}
