import { formatTime, formatDate, formatDateTime, BASE_URL, getHeaders } from './index.js'; 

// 定义借用资产接口
interface BorrowAsset {
  borrowId: number;
  assetId: number;
  assetName: string;
  borrowDate: string;
  returnDate: string | null;
  actualReturnDate: string | null;
  borrowerId: string;
  borrowerName: string;
  borrowerMobile: string;
  borrowDepartmentId: string | null;
  borrowDepartmentName: string | null;
  location: string | null;
  lenderId: string | null;
  lenderName: string | null;
  lenderMobile: string | null;
  approverId: string | null;
  approverName: string | null;
  approverMobile: string | null;
  registrantId: string | null;
  registrantName: string | null;
  registrantMobile: string | null;
  registrantDate: string | null;
  isReturn: number;
  note: string;
  deleteFlag: number;
}

// 定义分页响应接口
interface PagedResponse<T> {
  total: number;
  list: T[];
  pageNum: number;
  pageSize: number;
  size: number;
  startRow: number;
  endRow: number;
  pages: number;
  prePage: number;
  nextPage: number;
  isFirstPage: boolean;
  isLastPage: boolean;
  hasPreviousPage: boolean;
  hasNextPage: boolean;
  navigatePages: number;
  navigatepageNums: number[];
  navigateFirstPage: number;
  navigateLastPage: number;
}

// 定义 API 响应接口
interface ApiResponse<T> {
  code: number;
  msg: string;
  token: string | null;
  data: T;
}

// 借用列表
/* {
  "code": 0,
  "msg": "查询成功",
  "token": null,
  "data": {
    "total": 16,
    "list": [
      {
        "borrowId": 49,
        "assetId": 83,
        "assetName": "和法国哈哈",
        "borrowDate": "2025-09-07",
        "returnDate": "2025-09-01",
        "actualReturnDate": null,
        "borrowerId": "40288083894a5a38018999ea74ff0135",
        "borrowerName": "熊三",
        "borrowerMobile": "123",
        "borrowDepartmentId": null,
        "borrowDepartmentName": null,
        "location": null,
        "lenderId": null,
        "lenderName": null,
        "lenderMobile": null,
        "approverId": null,
        "approverName": null,
        "approverMobile": null,
        "registrantId": "null",
        "registrantName": null,
        "registrantMobile": null,
        "registrantDate": "2025-09-29",
        "isReturn": 0,
        "note": "123213",
        "deleteFlag": 0
      },...
    ],
    "pageNum": 1,
    "pageSize": 10,
    "size": 10,
    "startRow": 1,
    "endRow": 10,
    "pages": 2,
    "prePage": 0,
    "nextPage": 2,
    "isFirstPage": true,
    "isLastPage": false,
    "hasPreviousPage": false,
    "hasNextPage": true,
    "navigatePages": 8,
    "navigatepageNums": [
      1,
      2
    ],
    "navigateFirstPage": 1,
    "navigateLastPage": 2
  }
} */
export function getLentAssetsList(page: number, pageSize: number, searchParams: any): Promise<ApiResponse<PagedResponse<BorrowAsset>>> {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${BASE_URL}/api/asset/borrow/page`,
      method: 'POST',
      header: getHeaders(),
      data: {
        pageNum: page,
        pageSize,
        ...searchParams
      },
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data as ApiResponse<PagedResponse<BorrowAsset>>);
        } else {
          reject(res);
        }
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
}
