import type { MockMethod } from './types'

const productionItems = [
  { id: 1, date: '2026-04-25', machineName: '西-1.8', programName: '1566.NC', quantity: 580, runTime: '4h20m', cuttingTime: '3h50m', dataStatus: 'normal', isAdjusted: 0, adjustedQuantity: null },
  { id: 2, date: '2026-04-25', machineName: '东-2.5', programName: 'A456.NC', quantity: null, runTime: null, cuttingTime: null, dataStatus: 'data_missing', isAdjusted: 0, adjustedQuantity: null },
  { id: 3, date: '2026-04-25', machineName: '北-4.1', programName: 'B789.NC', quantity: 310, runTime: '2h10m', cuttingTime: '1h50m', dataStatus: 'normal', isAdjusted: 1, adjustedQuantity: 320 },
]

const mock: MockMethod[] = [
  { url: '/mock-api/admin/production/daily-summary', method: 'get', response: () => ({ code: 0, data: { totalQuantity: 8520, activeMachineCount: 142, totalCuttingTime: '580h', avgQuantityPerMachine: 60 } }) },
  { url: '/mock-api/admin/production/daily', method: 'get', response: () => ({ code: 0, data: { items: productionItems, total: 1200, page: 1, pageSize: 20 } }) },
  { url: '/mock-api/admin/production/adjust', method: 'post', response: () => ({ code: 0, message: 'success', data: null }) },
  { url: '/mock-api/admin/production/adjustment-history', method: 'get', response: (config: any) => {
      const rid = config?.query?.recordId
      if (rid && Number(rid) === 1) {
        return { code: 0, data: { items: [
          { createdAt: '2026-04-25T15:30:00', oldValue: 310, newValue: 320, reason: '传感器计数偏差，手工校准', operator: '系统' },
          { createdAt: '2026-04-26T09:45:00', oldValue: 320, newValue: 315, reason: '现场核对，微调', operator: '操作员A' }
        ] } }
      }
      // 其他记录ID返回空历史
      return { code: 0, data: { items: [] } }
    } },
  { url: '/mock-api/admin/production/export', method: 'get', response: () => ({ code: 0, data: null }) },
  { url: '/mock-api/admin/workshop/list', method: 'get', response: () => ({ code: 0, data: { items: [{ id: 1, name: 'A栋' }, { id: 2, name: 'B栋' }, { id: 3, name: 'C栋' }] } }) },
  { url: '/mock-api/admin/machine/list', method: 'get', response: () => ({ code: 0, data: { items: [{ id: 1, name: '西-1.8' }, { id: 2, name: '西-1.10' }, { id: 3, name: '东-2.0' }] } }) },
  { url: '/mock-api/admin/worker/list', method: 'get', response: () => ({ code: 0, data: { items: [{ id: 1, name: '张三' }, { id: 2, name: '李四' }] } }) },
]

export default mock
