import request from './request'

// 看板
export const getDashboardSummary = () => request.get('/dashboard/summary')

// 物料跟踪
export const getCoils = params => request.get('/material/coils', { params })
export const getCoil = coilNo => request.get(`/material/coils/${coilNo}`)
export const createCoil = data => request.post('/material/coils', data)
export const updateCoil = (coilNo, data) => request.put(`/material/coils/${coilNo}`, data)
export const getTracking = params => request.get('/material/tracking', { params })

// 实绩管理
export const getProductionRecords = params => request.get('/production/', { params })
export const createProductionRecord = data => request.post('/production/', data)
export const updateProductionRecord = (id, data) => request.put(`/production/${id}`, data)

// 计划管理
export const getPlans = params => request.get('/plan/', { params })
export const createPlan = data => request.post('/plan/', data)
export const updatePlan = (id, data) => request.put(`/plan/${id}`, data)
export const confirmPlan = id => request.patch(`/plan/${id}/confirm`)
export const startProducing = id => request.patch(`/plan/${id}/start`)   // 移动到上卷鞍座(兼容)
export const moveToSaddle = id => request.patch(`/plan/${id}/start`)
export const movePlan = (id, position) => request.patch(`/plan/${id}/move`, null, { params: { position } })
export const getPositions = () => request.get('/plan/positions/all')
export const commitProducing = id => request.patch(`/plan/${id}/commit`) // 投入生产
export const getSaddle = () => request.get('/plan/saddle/current')
export const seedPlans = (count = 50) => request.post('/plan/seed', null, { params: { count } })
export const getLastPlanTemplate = () => request.get('/plan/last-template')

// 成本管理
export const getCostItems = () => request.get('/cost/items')
export const getCostRecords = params => request.get('/cost/', { params })
export const createCostRecord = data => request.post('/cost/', data)
export const updateCostRecord = (id, data) => request.put(`/cost/${id}`, data)
export const deleteCostRecord = id => request.delete(`/cost/${id}`)

// 停机管理
export const getDowntimeCategories = () => request.get('/downtime/categories')
export const getDowntimeRecords = params => request.get('/downtime/', { params })
export const createDowntime = data => request.post('/downtime/', data)
export const updateDowntime = (id, data) => request.put(`/downtime/${id}`, data)

// 设备管理
export const getEquipments = params => request.get('/equipment/', { params })
export const createEquipment = data => request.post('/equipment/', data)
export const updateEquipment = (id, data) => request.put(`/equipment/${id}`, data)
export const getEquipmentMaintenance = (id, params) => request.get(`/equipment/${id}/maintenance`, { params })
export const createMaintenance = data => request.post('/equipment/maintenance', data)

// 报文监控
export const getMessageLogs = params => request.get('/message/logs', { params })
export const getMessageLog = id => request.get(`/message/logs/${id}`)

// 工艺预测模型
export const predictAcidSpeed  = data => request.post('/prediction/acid-speed', data)
export const predictTension     = data => request.post('/prediction/tension', data)
export const predictQuality     = data => request.post('/prediction/quality', data)
export const predictConsumption = data => request.post('/prediction/consumption', data)

// 模型校准
export const getCalibration         = ()     => request.get('/prediction/calibration')
export const calibrateAcidSpeed     = data   => request.post('/prediction/calibration/acid-speed', data)
export const calibrateTension       = data   => request.post('/prediction/calibration/tension', data)
export const calibrateQuality       = data   => request.post('/prediction/calibration/quality', data)
export const resetCalibration       = model  => request.post(`/prediction/calibration/reset/${model}`)

// 设备巡检
export const getChecklists = params => request.get('/inspection/checklists', { params })
export const createChecklist = data => request.post('/inspection/checklists', data)
export const updateChecklist = (id, data) => request.put(`/inspection/checklists/${id}`, data)
export const getChecklistItems = id => request.get(`/inspection/checklists/${id}/items`)
export const createChecklistItem = (checklistId, data) => request.post('/inspection/checklist-items', data, { params: { checklist_id: checklistId } })
export const getInspectionRecords = params => request.get('/inspection/records', { params })
export const createInspectionRecord = data => request.post('/inspection/records', data)
export const getInspectionRecordDetails = id => request.get(`/inspection/records/${id}/details`)

// 质量管理
export const getQcTasks = params => request.get('/quality/tasks', { params })
export const createQcTask = data => request.post('/quality/tasks', data)
export const updateQcTask = (id, data) => request.put(`/quality/tasks/${id}`, data)
export const deleteQcTask = id => request.delete(`/quality/tasks/${id}`)
export const getQcTaskItems = taskId => request.get(`/quality/tasks/${taskId}/items`)
export const createQcTaskItem = data => request.post('/quality/task-items', data)
export const updateQcTaskItem = (id, data) => request.put(`/quality/task-items/${id}`, data)
export const getQcDefects = params => request.get('/quality/defects', { params })
export const createQcDefect = data => request.post('/quality/defects', data)
export const updateQcDefect = (id, data) => request.put(`/quality/defects/${id}`, data)
export const deleteQcDefect = id => request.delete(`/quality/defects/${id}`)
export const getQcDefectsByCoil = coilNo => request.get(`/quality/defects/by-coil/${encodeURIComponent(coilNo)}`)
export const bulkSaveQcDefects = data => request.post('/quality/defects/bulk-save', data)
