import api, { PageResponse, unwrap } from './request';

export interface LoginLogResp {
  logId: number;
  userId?: number;
  username?: string;
  loginType: string;
  ipAddress?: string;
  userAgent?: string;
  failReason?: string;
  loginAt?: string;
}

export interface ApiAccessLogResp {
  logId: number;
  userId?: number;
  username?: string;
  requestMethod: string;
  requestUrl: string;
  responseStatus?: number;
  responseTime?: number;
  ipAddress?: string;
  errorMessage?: string;
  createdAt?: string;
}

export interface DataChangeLogResp {
  logId: number;
  tableName: string;
  recordId?: string;
  actionType: string;
  changeData?: any;
  changeReason?: string;
  userId?: number;
  username?: string;
  ipAddress?: string;
  menuCode?: string;
  createdAt?: string;
}

export const logApi = {
  login:  (p: { pageNum?: number; pageSize?: number; username?: string; startDate?: string; endDate?: string }) =>
    unwrap<PageResponse<LoginLogResp>>(api.get('/api/system/logs/login', { params: p })),
  api:    (p: { pageNum?: number; pageSize?: number; username?: string; startDate?: string; endDate?: string }) =>
    unwrap<PageResponse<ApiAccessLogResp>>(api.get('/api/system/logs/api', { params: p })),
  change: (p: { pageNum?: number; pageSize?: number; tableName?: string; username?: string; startDate?: string; endDate?: string }) =>
    unwrap<PageResponse<DataChangeLogResp>>(api.get('/api/system/logs/data-change', { params: p })),
};
