import { request } from '@/utils'

const baseValuationDetail = {
  valuation_result: 1180000,
  created_at: '2024-11-10T09:30:00Z',
  reviewed_at: null,
  status: 'pending',
  admin_notes: null,
  asset_name: '蜀绣传承精品',
  institution: '天府非遗文化发展有限公司',
  industry: '文化创意',
  annual_revenue: 980000,
  rd_investment: 165000,
  three_year_income: [890000, 975000, 1180000],
  funding_status: '国家资助',
  inheritor_level: '市级传承人',
  inheritor_age_count: [4, 6, 2],
  inheritor_certificates: [
    'https://dummyimage.com/120x80/edf2ff/409eff&text=证书A1',
    'https://dummyimage.com/120x80/fef6f0/f0a020&text=证书A2',
  ],
  heritage_level: '国家级非遗',
  heritage_asset_level: '一级保护',
  patent_application_no: '1111111,2222222',
  historical_evidence: {
    artifacts: 1,
    ancient_literature: 2,
    inheritor_testimony: 0,
    modern_research: 3,
  },
  patent_certificates: ['https://dummyimage.com/120x80/e8f5e9/34a853&text=专利1'],
  pattern_images: ['https://dummyimage.com/120x80/f3e8ff/9c27b0&text=纹样1'],
  application_maturity: '推广阶段',
  application_coverage: '全国覆盖',
  cooperation_depth: '品牌联名',
  offline_activities: 4,
  platform_accounts: {
    bilibili: { account: 'B站@蜀绣', likes: 1260, comments: 320, shares: 188 },
  },
  sales_volume: 5200,
  link_views: 86500,
  circulation: '500-1000份',
  last_market_activity: '近3个月',
  monthly_transaction: '50-100万元',
  price_fluctuation: [1200, 3200],
  model_value_b: 1250000,
  market_value_c: 1180000,
  final_value_ab: 1220000,
  dynamic_pledge_rate: 0.62,
  calculation_result: {
    flow: [
      {
        title: '基础估值',
        description: '基于近三年收益与研发投入的模型估值',
        value: '¥1,250,000',
      },
      {
        title: '市场对标',
        description: '结合同类资产市场成交价修正',
        value: '¥1,180,000',
      },
      {
        title: '综合校准',
        description: '叠加ESG、政策匹配度得出最终估值',
        value: '¥1,220,000',
      },
    ],
  },
}

const valuationRecords = [
  {
    id: 2001,
    phone: '13800138001',
    wechat: 'zhangsan_wx',
  },
  {
    id: 2002,
    phone: '13800138002',
    wechat: 'lisi2024',
    valuation_result: 880000,
    created_at: '2024-11-09T14:20:00Z',
    reviewed_at: '2024-11-09T16:45:00Z',
    status: 'approved',
    admin_notes: '评估结果合理，已通过审核',
    asset_name: '景泰蓝掐丝珐琅',
    institution: '京华非遗研究院',
    application_maturity: '成熟期',
    application_coverage: '华北地区',
    cooperation_depth: '科技载体',
    platform_accounts: {
      douyin: { account: '抖音@景泰蓝工坊', likes: 2350, comments: 610, shares: 302 },
    },
    price_fluctuation: [980, 2680],
    calculation_result: {
      flow: [
        {
          title: '基础估值',
          description: '模型估算品牌溢价后得出结果',
          value: '¥900,000',
        },
        {
          title: '市场对标',
          description: '对比近六个月文博拍卖价格',
          value: '¥860,000',
        },
        {
          title: '综合校准',
          description: '结合政策扶持与线上声量校准',
          value: '¥880,000',
        },
      ],
    },
  },
  {
    id: 2003,
    phone: '13800138003',
    wechat: 'wangwu_user',
    valuation_result: 2100000,
    created_at: '2024-11-08T16:45:00Z',
    reviewed_at: '2024-11-08T18:30:00Z',
    status: 'approved',
    admin_notes: '评估价格偏高，但审核通过',
    asset_name: '苗绣银饰',
    institution: '黔锦民族文化有限公司',
    industry: '民族工艺',
    funding_status: '地方配套资金',
    inheritor_level: '国家级代表性传承人',
    inheritor_age_count: [2, 3, 1],
    application_coverage: '西南片区',
    platform_accounts: {
      kuaishou: { account: '快手@苗绣手作', likes: 1800, comments: 420, shares: 210 },
    },
    price_fluctuation: [2600, 5200],
  },
  {
    id: 2004,
    phone: '13800138004',
    wechat: 'zhaoliu_vip',
    valuation_result: 560000,
    created_at: '2024-11-07T11:15:00Z',
    status: 'pending',
    asset_name: '景德镇青花',
    institution: '景尚文化传播有限公司',
    industry: '陶瓷制造',
    funding_status: '社会资本',
    platform_accounts: {
      bilibili: { account: 'B站@青花研习社', likes: 860, comments: 146, shares: 98 },
    },
    price_fluctuation: [560, 1200],
  },
  {
    id: 2005,
    phone: '13800138005',
    wechat: 'sunqi888',
    valuation_result: 1680000,
    created_at: '2024-11-06T08:30:00Z',
    reviewed_at: '2024-11-06T10:15:00Z',
    status: 'approved',
    admin_notes: '评估数据完整，审核通过',
    asset_name: '藏医药香丸',
    institution: '高原本草研究中心',
    industry: '中医药',
    application_coverage: '西藏及周边',
    cooperation_depth: '国家外交礼品',
    platform_accounts: {
      douyin: { account: '抖音@藏医手作', likes: 3120, comments: 815, shares: 356 },
    },
    price_fluctuation: [3200, 7600],
  },
  {
    id: 2006,
    phone: '13800138006',
    wechat: 'zhouba2024',
    valuation_result: 950000,
    created_at: '2024-11-05T13:20:00Z',
    status: 'pending',
    asset_name: '苏绣屏风',
    institution: '苏澜绣坊',
    funding_status: '企业自筹',
    platform_accounts: {
      bilibili: { account: 'B站@苏绣博物馆', likes: 980, comments: 240, shares: 130 },
    },
    price_fluctuation: [1500, 3600],
  },
  {
    id: 2007,
    phone: '13800138007',
    wechat: 'wujiu_user',
    valuation_result: 3200000,
    created_at: '2024-11-04T15:45:00Z',
    reviewed_at: '2024-11-04T17:20:00Z',
    status: 'approved',
    admin_notes: '高价值资产，评估结果准确',
    asset_name: '宋锦织造',
    institution: '苏州织造研究所',
    funding_status: '国家重点补贴',
    inheritor_age_count: [6, 8, 4],
    application_maturity: '成熟期',
    cooperation_depth: '科技载体',
    platform_accounts: {
      douyin: { account: '抖音@宋锦织造', likes: 4800, comments: 1020, shares: 520 },
    },
  },
  {
    id: 2008,
    phone: '13800138008',
    wechat: 'zhengshi_vip',
    valuation_result: 750000,
    created_at: '2024-11-03T10:10:00Z',
    reviewed_at: '2024-11-03T12:00:00Z',
    status: 'approved',
    admin_notes: '评估流程规范，结果可信',
    asset_name: '黄梅挑花',
    institution: '徽楚非遗中心',
    cooperation_depth: '品牌联名',
    price_fluctuation: [980, 1800],
  },
  {
    id: 2009,
    phone: '13800138009',
    wechat: 'chenjun2024',
    valuation_result: 1890000,
    created_at: '2024-11-02T14:30:00Z',
    status: 'pending',
    asset_name: '黎锦织造',
    institution: '海南黎锦工坊',
    funding_status: '国家资助',
    application_coverage: '华南地区',
  },
  {
    id: 2010,
    phone: '13800138010',
    wechat: 'liuxia_user',
    valuation_result: 430000,
    created_at: '2024-11-01T11:45:00Z',
    reviewed_at: '2024-11-01T13:30:00Z',
    status: 'approved',
    admin_notes: '低价值资产，评估合理',
    asset_name: '大漆工艺',
    institution: '榫卯器物社',
    funding_status: '地方专项',
    cooperation_depth: '品牌联名',
    platform_accounts: {
      bilibili: { account: 'B站@大漆工坊', likes: 420, comments: 75, shares: 33 },
    },
  },
  {
    id: 2011,
    phone: '13800138011',
    wechat: 'zhaolei2024',
    valuation_result: 2100000,
    created_at: '2024-10-31T09:20:00Z',
    reviewed_at: '2024-10-31T11:00:00Z',
    status: 'approved',
    admin_notes: '评估报告详细，数据支撑充分',
    asset_name: '龙泉青瓷',
    institution: '浙瓷非遗研究院',
    cooperation_depth: '科技载体',
  },
  {
    id: 2012,
    phone: '13800138012',
    wechat: 'sunmei_vip',
    valuation_result: 680000,
    created_at: '2024-10-30T16:15:00Z',
    status: 'pending',
    asset_name: '侗锦织造',
    institution: '黔东南侗锦合作社',
    funding_status: '社会资本',
  },
]

const mockValuationDetails = valuationRecords.map((record) => ({
  ...baseValuationDetail,
  ...record,
}))

const mockAppUsers = [
  {
    id: 11111111,
    phone: '15021982682',
    wechat: 'f1498480844',
    created_at: '2024-01-15T10:30:00Z',
    notes: '测试用户1',
    remaining_count: 1,
    user_type: '体验用户',
  },
  {
    id: 11111112,
    phone: '13800138002',
    wechat: 'wx_limming2024',
    created_at: '2024-02-20T14:20:00Z',
    notes: '付费用户',
    remaining_count: 5,
    user_type: '付费用户',
  },
  {
    id: 11111113,
    phone: '13800138003',
    wechat: null,
    created_at: '2024-03-10T08:45:00Z',
    notes: null,
    remaining_count: 0,
    user_type: '体验用户',
  },
  {
    id: 11111114,
    phone: '13800138004',
    wechat: 'chenjun_vip',
    created_at: '2024-04-05T11:30:00Z',
    notes: 'VIP用户',
    remaining_count: 10,
    user_type: 'VIP',
  },
  {
    id: 11111115,
    phone: '13800138005',
    wechat: 'liuxia888',
    created_at: '2024-05-12T16:15:00Z',
    notes: '体验用户',
    remaining_count: 3,
    user_type: '体验用户',
  },
  {
    id: 11111116,
    phone: '13800138006',
    wechat: null,
    created_at: '2024-06-18T09:00:00Z',
    notes: '新注册用户',
    remaining_count: 2,
    user_type: '体验用户',
  },
  {
    id: 11111117,
    phone: '13800138007',
    wechat: 'zhaolei2024',
    created_at: '2024-07-22T12:45:00Z',
    notes: null,
    remaining_count: 0,
    user_type: '体验用户',
  },
  {
    id: 11111118,
    phone: '13800138008',
    wechat: 'sunmei_user',
    created_at: '2024-08-30T15:20:00Z',
    notes: '活跃用户',
    remaining_count: 7,
    user_type: 'VIP',
  },
]

const defaultInvoiceHeaders = [
  {
    company_name: '成都文创科技有限公司',
    tax_number: '91510100MA7XYZ1234',
    register_address: '四川省成都市高新区天府三街666号',
    register_phone: '028-66666666',
    bank_name: '招商银行成都分行',
    bank_account: '6225 6666 8888 0000',
    email: 'finance@scwenchuang.com',
  },
  {
    company_name: '天府文化发展有限公司',
    tax_number: '91510100678912345K',
    register_address: '四川省成都市武侯区科华北路88号',
    register_phone: '028-12345678',
    bank_name: '中国工商银行成都分行',
    bank_account: '6212 8888 0000 9999',
    email: 'invoice@tfculture.com',
  },
]

const defaultOperationLogs = [
  {
    time: '2025-10-31 18:30:30',
    operator: 'admin',
    records: ['剩余估值次数：0 -> 1', '类型：付费估值', '备注：新用户'],
  },
  {
    time: '2025-10-31 18:30:30',
    operator: 'admin',
    records: ['剩余估值次数：2 -> 1', '类型：付费估值', '备注：退款'],
  },
  {
    time: '2025-10-31 18:30:30',
    operator: 'admin',
    records: ['用户备注：111111111111 -> 22222222222222222222'],
  },
]

export default {
  login: (data) => request.post('/base/access_token', data, { noNeedToken: true }),
  getUserInfo: () => request.get('/base/userinfo'),
  getUserMenu: () => request.get('/base/usermenu'),
  getUserApi: () => request.get('/base/userapi'),
  // profile
  updatePassword: (data = {}) => request.post('/base/update_password', data),
  // users
  getUserList: (params = {}) => request.get('/user/list', { params }),
  getUserById: (params = {}) => request.get('/user/get', { params }),
  createUser: (data = {}) => request.post('/user/create', data),
  updateUser: (data = {}) => request.post('/user/update', data),
  deleteUser: (params = {}) => request.delete(`/user/delete`, { params }),
  resetPassword: (data = {}) => request.post(`/user/reset_password`, data),
  // role
  getRoleList: (params = {}) => request.get('/role/list', { params }),
  createRole: (data = {}) => request.post('/role/create', data),
  updateRole: (data = {}) => request.post('/role/update', data),
  deleteRole: (params = {}) => request.delete('/role/delete', { params }),
  updateRoleAuthorized: (data = {}) => request.post('/role/authorized', data),
  getRoleAuthorized: (params = {}) => request.get('/role/authorized', { params }),
  // menus
  getMenus: (params = {}) => request.get('/menu/list', { params }),
  createMenu: (data = {}) => request.post('/menu/create', data),
  updateMenu: (data = {}) => request.post('/menu/update', data),
  deleteMenu: (params = {}) => request.delete('/menu/delete', { params }),
  // apis
  getApis: (params = {}) => request.get('/api/list', { params }),
  createApi: (data = {}) => request.post('/api/create', data),
  updateApi: (data = {}) => request.post('/api/update', data),
  deleteApi: (params = {}) => request.delete('/api/delete', { params }),
  refreshApi: (data = {}) => request.post('/api/refresh', data),
  // depts
  getDepts: (params = {}) => request.get('/dept/list', { params }),
  createDept: (data = {}) => request.post('/dept/create', data),
  updateDept: (data = {}) => request.post('/dept/update', data),
  deleteDept: (params = {}) => request.delete('/dept/delete', { params }),
  // auditlog
  getAuditLogList: (params = {}) => request.get('/auditlog/list', { params }),
  // app users (客户端用户管理) - 使用现有的后端接口
  getAppUserList: (params = {}) => {
    // 模拟分页和搜索
    let filteredUsers = [...mockAppUsers]
    
    // 手机号搜索
    if (params.phone) {
      filteredUsers = filteredUsers.filter(user => 
        user.phone.includes(params.phone)
      )
    }
    
    // 微信号搜索
    if (params.wechat) {
      filteredUsers = filteredUsers.filter(user => 
        user.wechat && user.wechat.includes(params.wechat)
      )
    }
    
    // 注册时间筛选（日期范围）
    if (params.created_at && Array.isArray(params.created_at) && params.created_at.length === 2) {
      const [startTime, endTime] = params.created_at
      filteredUsers = filteredUsers.filter(user => {
        if (!user.created_at) return false
        const userTime = new Date(user.created_at).getTime()
        return userTime >= startTime && userTime <= endTime
      })
    }

    // 分页处理
    const page = Number(params.page) || 1
    const pageSize = Number(params.page_size) || 10
    const startIndex = (page - 1) * pageSize
    const endIndex = startIndex + pageSize
    const paginatedUsers = filteredUsers.slice(startIndex, endIndex)

    // 返回 Promise 模拟异步请求
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          data: paginatedUsers,
          total: filteredUsers.length,
          page,
          page_size: pageSize,
        })
      }, 300)
    })
  },
  getAppUserById: (params = {}) =>
    new Promise((resolve) => {
      const id = Number(params.id)
      const user = mockAppUsers.find((item) => item.id === id) || {}
      setTimeout(() => {
        resolve({
          baseInfo: {
            id: user.id,
            phone: user.phone,
            wechat: user.wechat,
            register_time: user.created_at,
            notes: user.notes,
            remaining_count: user.remaining_count,
            user_type: user.user_type || '体验用户',
          },
          invoiceHeaders: defaultInvoiceHeaders,
          operationLogs: defaultOperationLogs,
        })
      }, 300)
    }),
  createAppUser: (data = {}) => request.post('/app-user/register', data),
  updateAppUser: (data = {}) => request.post('/app-user/update', data),
  deleteAppUser: (params = {}) => request.delete('/app-user/delete', { params }),
  // invoice (开票记录)
  getInvoiceList: (params = {}) => {
    // Mock 数据
    const mockInvoices = [
      {
        id: 1001,
        created_at: '2024-11-10T09:30:00Z',
        ticket_type: 'electronic',
        phone: '13800138001',
        email: 'zhangsan@company1.com',
        company_name: '北京科技有限公司',
        tax_number: '91110000123456789A',
        register_address: '北京市朝阳区科技园区A座1001室',
        register_phone: '010-12345678',
        bank_name: '中国工商银行北京分行',
        bank_account: '6222021234567890123',
        invoice_type: 'special',
        status: 'pending'
      },
      {
        id: 1002,
        created_at: '2024-11-09T14:20:00Z',
        ticket_type: 'paper',
        phone: '13800138002',
        email: 'lisi@company2.com',
        company_name: '上海贸易股份有限公司',
        tax_number: '91310000987654321B',
        register_address: '上海市浦东新区金融街B座2002室',
        register_phone: '021-87654321',
        bank_name: '中国建设银行上海分行',
        bank_account: '6217001234567890124',
        invoice_type: 'normal',
        status: 'invoiced'
      },
      {
        id: 1003,
        created_at: '2024-11-08T16:45:00Z',
        ticket_type: 'electronic',
        phone: '13800138003',
        email: 'wangwu@company3.com',
        company_name: '深圳创新科技有限公司',
        tax_number: '91440300456789012C',
        register_address: '深圳市南山区高新技术园C座3003室',
        register_phone: '0755-23456789',
        bank_name: '招商银行深圳分行',
        bank_account: '6214851234567890125',
        invoice_type: 'special',
        status: 'rejected'
      },
      {
        id: 1004,
        created_at: '2024-11-07T11:15:00Z',
        ticket_type: 'paper',
        phone: '13800138004',
        email: 'zhaoliu@company4.com',
        company_name: '广州制造业集团有限公司',
        tax_number: '91440100789012345D',
        register_address: '广州市天河区商务中心D座4004室',
        register_phone: '020-34567890',
        bank_name: '中国银行广州分行',
        bank_account: '6013821234567890126',
        invoice_type: 'normal',
        status: 'pending'
      },
      {
        id: 1005,
        created_at: '2024-11-06T08:30:00Z',
        ticket_type: 'electronic',
        phone: '13800138005',
        email: 'sunqi@company5.com',
        company_name: '杭州互联网科技有限公司',
        tax_number: '91330100012345678E',
        register_address: '杭州市西湖区互联网小镇E座5005室',
        register_phone: '0571-45678901',
        bank_name: '浙商银行杭州分行',
        bank_account: '6228481234567890127',
        invoice_type: 'special',
        status: 'invoiced'
      },
      {
        id: 1006,
        created_at: '2024-11-05T13:20:00Z',
        ticket_type: 'paper',
        phone: '13800138006',
        email: 'zhouba@company6.com',
        company_name: '成都软件开发有限公司',
        tax_number: '91510100345678901F',
        register_address: '成都市高新区软件园F座6006室',
        register_phone: '028-56789012',
        bank_name: '中国农业银行成都分行',
        bank_account: '6230521234567890128',
        invoice_type: 'normal',
        status: 'pending'
      },
      {
        id: 1007,
        created_at: '2024-11-04T15:45:00Z',
        ticket_type: 'electronic',
        phone: '13800138007',
        email: 'wujiu@company7.com',
        company_name: '武汉新能源科技有限公司',
        tax_number: '91420100678901234G',
        register_address: '武汉市江汉区新能源产业园G座7007室',
        register_phone: '027-67890123',
        bank_name: '交通银行武汉分行',
        bank_account: '6222601234567890129',
        invoice_type: 'special',
        status: 'invoiced'
      },
      {
        id: 1008,
        created_at: '2024-11-03T10:10:00Z',
        ticket_type: 'paper',
        phone: '13800138008',
        email: 'zhengshi@company8.com',
        company_name: '西安电子商务有限公司',
        tax_number: '91610100901234567H',
        register_address: '西安市雁塔区电商产业园H座8008室',
        register_phone: '029-78901234',
        bank_name: '中信银行西安分行',
        bank_account: '6217711234567890130',
        invoice_type: 'normal',
        status: 'refunded'
      },
      {
        id: 1009,
        created_at: '2024-11-02T14:30:00Z',
        ticket_type: 'electronic',
        phone: '13800138009',
        email: 'wangwu@company9.com',
        company_name: '天津物流科技有限公司',
        tax_number: '91120000234567890I',
        register_address: '天津市滨海新区物流园I座9009室',
        register_phone: '022-89012345',
        bank_name: '民生银行天津分行',
        bank_account: '6226221234567890131',
        invoice_type: 'special',
        status: 'refunded'
      },
      {
        id: 1010,
        created_at: '2024-11-01T11:45:00Z',
        ticket_type: 'paper',
        phone: '13800138010',
        email: 'liuliu@company10.com',
        company_name: '重庆智能制造有限公司',
        tax_number: '91500000567890123J',
        register_address: '重庆市渝北区智能制造园J座1010室',
        register_phone: '023-90123456',
        bank_name: '华夏银行重庆分行',
        bank_account: '6228881234567890132',
        invoice_type: 'normal',
        status: 'rejected'
      }
    ]

    // 模拟分页和搜索
    let filteredInvoices = [...mockInvoices]
    
    // 手机号搜索
    if (params.phone) {
      filteredInvoices = filteredInvoices.filter(invoice => 
        invoice.phone.includes(params.phone)
      )
    }
    
    // 公司名称搜索
    if (params.company_name) {
      filteredInvoices = filteredInvoices.filter(invoice => 
        invoice.company_name.includes(params.company_name)
      )
    }
    
    // 公司税号搜索
    if (params.tax_number) {
      filteredInvoices = filteredInvoices.filter(invoice => 
        invoice.tax_number.includes(params.tax_number)
      )
    }
    
    // 状态筛选
    if (params.status) {
      filteredInvoices = filteredInvoices.filter(invoice => 
        invoice.status === params.status
      )
    }
    
    // 提交时间筛选
    if (params.created_at && Array.isArray(params.created_at) && params.created_at.length === 2) {
      const [startDate, endDate] = params.created_at
      filteredInvoices = filteredInvoices.filter(invoice => {
        const invoiceDate = new Date(invoice.created_at)
        return invoiceDate >= new Date(startDate) && invoiceDate <= new Date(endDate)
      })
    }

    // 分页处理
    const page = params.page || 1
    const pageSize = params.page_size || 10
    const startIndex = (page - 1) * pageSize
    const endIndex = startIndex + pageSize
    const paginatedInvoices = filteredInvoices.slice(startIndex, endIndex)

    // 返回 Promise 模拟异步请求
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          data: paginatedInvoices,
          total: filteredInvoices.length,
          page: page,
          page_size: pageSize
        })
      }, 300) // 模拟网络延迟
    })
  },
  getInvoiceById: (params = {}) => request.get('/invoice/detail', { params }),
  createInvoice: (data = {}) => request.post('/invoice/create', data),
  updateInvoice: (data = {}) => request.post('/invoice/update', data),
  deleteInvoice: (params = {}) => request.delete('/invoice/delete', { params }),
  updateInvoiceStatus: (data = {}) => request.post('/invoice/update-status', data),
  remindInvoice: (data = {}) => request.post('/invoice/remind', data),
  refundInvoice: (data = {}) => request.post('/invoice/refund', data),
  sendInvoice: (data = {}) => request.post('/invoice/send', data),
  // valuation (估值评估)
  getValuationList: (params = {}) => {
    // 模拟分页和搜索
    let filteredValuations = [...mockValuationDetails]
    
    // 手机号搜索
    if (params.phone) {
      filteredValuations = filteredValuations.filter(valuation => 
        valuation.phone.includes(params.phone)
      )
    }
    
    // 微信号搜索
    if (params.wechat) {
      filteredValuations = filteredValuations.filter(valuation => 
        valuation.wechat && valuation.wechat.includes(params.wechat)
      )
    }
    
    // 状态筛选
    if (params.status) {
      filteredValuations = filteredValuations.filter(valuation => 
        valuation.status === params.status
      )
    }
    
    // 提交时间筛选
    if (params.created_at && Array.isArray(params.created_at) && params.created_at.length === 2) {
      const [startDate, endDate] = params.created_at
      filteredValuations = filteredValuations.filter(valuation => {
        const valuationDate = new Date(valuation.created_at)
        return valuationDate >= new Date(startDate) && valuationDate <= new Date(endDate)
      })
    }

    // 分页处理
    const page = params.page || 1
    const pageSize = params.page_size || 10
    const startIndex = (page - 1) * pageSize
    const endIndex = startIndex + pageSize
    const paginatedValuations = filteredValuations.slice(startIndex, endIndex).map((item) => ({
      id: item.id,
      phone: item.phone,
      wechat: item.wechat,
      valuation_result: item.valuation_result,
      created_at: item.created_at,
      reviewed_at: item.reviewed_at,
      status: item.status,
      admin_notes: item.admin_notes,
    }))

    // 返回 Promise 模拟异步请求
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          data: paginatedValuations,
          total: filteredValuations.length,
          page: page,
          page_size: pageSize
        })
      }, 300) // 模拟网络延迟
    })
  },
  getValuationById: (params = {}) => {
    const id = Number(params.valuation_id || params.id)
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        const detail = mockValuationDetails.find((item) => item.id === id)
        if (detail) {
          resolve({ data: detail })
        } else {
          reject({ code: 404, message: '未找到估值详情' })
        }
      }, 200)
    })
  },
  createValuation: (data = {}) => request.post('/valuation', data),
  updateValuation: (data = {}) => request.put(`/valuation/${data.id}`, data),
  deleteValuation: (params = {}) => request.delete(`/valuation/${params.valuation_id}`),
  approveValuation: (data = {}) => request.post(`/valuation/${data.valuation_id}/approve`, data),
  rejectValuation: (data = {}) => request.post(`/valuation/${data.valuation_id}/reject`, data),
  updateValuationNotes: (data = {}) => request.put(`/valuation/${data.valuation_id}/admin-notes`, data),
}
