import { http } from './index';

export interface LoginParams {
  account: string;
  password: string;
  role: string;
}

export interface LoginResponse {
  token: string;
  user: {
    id: number;
    name: string;
    role: 'admin' | 'school' | 'teacher';
    tenantId?: number;
    tenantName?: string;
    email?: string;
    phone?: string;
  };
}

export interface UserProfile {
  id: number;
  name: string;
  role: 'admin' | 'school' | 'teacher';
  tenantId?: number;
  tenantName?: string;
  email?: string;
  phone?: string;
  avatar?: string;
}

// 登录
export function login(params: LoginParams): Promise<LoginResponse> {
  return http.post('/auth/login', params);
}

// 登出
export function logout(): Promise<void> {
  return http.post('/auth/logout');
}

// 刷新Token
export function refreshToken(): Promise<{ token: string }> {
  return http.post('/auth/refresh');
}

// 获取当前用户信息
export function getProfile(): Promise<UserProfile> {
  return http.get('/auth/profile');
}
