import { requestClient } from '#/api/request';
import type { friendRecord } from '#/model/type';

export interface UserData {
  data: object[];
  total: number;
  sum: number;
  psum: number;
  nsum: number;
}
export interface UserLogAssetParam {
  Id: number;
  Event?: string;
  StartTime?: number;
  EndTime?: number;
  ItemId?: number;
  PageSize?: number;
  CurrentPage?: number;
  AppId?: number;
  Node?: number;
}
export interface UserLogOrder {
  Id: number;
  Time: number;
  Type: number;
  Diff: number;
  ChessId: ChessType[];
}

export interface ChessType {
  Id: string;
  Icon: string;
}
export interface heatType {
  date: string;
  value: number;
}
export interface UserLogInfo {
  AreaId: number;
  Charge: number;
  Level: number;
  Name: string;
  Star: number;
  Login: number;
  Energy: number;
  Diamond: number;
  Mac: string;
  Cumulative: number;
  TodayCumulative: number;
  Bonus?: number;
  Code?: string;
  RegisterTime: number;
  Ban?: number;
  Face?:number;
  Order: UserLogOrder[];
  ChessMap?:string;
  ChessBuffer?: Record<string, number>;
  Heatmap?: heatType[];
  ActLog?:actlog[];
  MaxCharge?: number;
  FriendList?: friendRecord[];
  AdWatch?: number;
}

export interface actlog {
 Time: number;
  Type: number;
  Param: string;
}

export interface UserOrder {
  Id: number;
  AppId?: number;
  ServerId?: number;
  OrderId: string;
  Price: number;
  PayChannelOrderId: string;
  ProductId: number;
  CreateTime: number;
  PayTime: number;
  PayType: number;
  Param: string;
  CreateTimeStr?: string;
  PayTimeStr?: string;
  PayStatus?:number;
  ReissueAuditId?: number;
  ReissueStatus?: number;
  ReissueReason?: string;
  ReissueApplicant?: string;
  ReissueReviewer?: string;
  ReissueReviewTime?: number;
  ReissueRemark?: string;
  ReissueThirdOrder?: string;
}

export namespace OrderReissueApi {
  export interface ApplyParams {
    AppId: number;
    OrderId: string;
    Reason: string;
    ServerId: number;
    ThirdPartyOrderId: string;
    Uid: number;
  }

  export interface ReviewParams {
    audit_id: number;
    review_remark?: string;
  }
}

export async function getUserLogAssetApi(data: UserLogAssetParam) {
  return requestClient.post<UserData>('/log/asset', data);
}

export async function getUserlogEventApi(data: UserLogAssetParam) {
  return requestClient.post<UserData>('/log/event', data);
}

export async function getUserlogInfoApi(data: UserLogAssetParam) {
  return requestClient.post<UserLogInfo>('/log/user', data);
}

export async function getUserlogOrderApi(data: UserLogAssetParam) {
  return requestClient.post<UserOrder>('/log/order', data);
}

export async function addOrderReissueApi(data: OrderReissueApi.ApplyParams) {
  return requestClient.post('/log/order/reissue/apply', data);
}

export async function approveOrderReissueApi(data: OrderReissueApi.ReviewParams) {
  return requestClient.post('/log/order/reissue/approve', data);
}

export async function rejectOrderReissueApi(data: OrderReissueApi.ReviewParams) {
  return requestClient.post('/log/order/reissue/reject', data);
}

export namespace LoginCountApi {
  export interface Params {
    Appid: number;
    Id: number;
    month: string;
  }
  export interface LoginDailyCount {
    date: string;
    count: number;
  }
  export interface Result {
    month: string;
    total: number;
    data: LoginDailyCount[];
  }
}

export async function getLoginCountByMonthApi(params: LoginCountApi.Params) {
  return requestClient.post<LoginCountApi.Result>(
    '/log/loginCountByMonth',
    params,
  );
}
