package com.zksy.base.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zksy.base.domain.WorkOrder;
import com.zksy.base.domain.WorkOrderLog;

import java.util.Date;
import java.util.List;

/**
 * 业务工单管理 Service（独立于已有 WorkOrderService）
 */
public interface BusinessWorkOrderService extends IService<WorkOrder> {

    /**
     * 分页查询工单列表（支持多条件筛选+排序）
     * @param equipmentType 设备类型：gas-燃气 drainage-排水，为空查询全部
     */
    IPage<WorkOrder> selectWorkOrderList(Integer orderType, Integer orderLevel,
                                         Integer orderStatus, String deviceCode,
                                         String keyword, String equipmentType,
                                         Integer pageNum, Integer pageSize);

    /**
     * 查询工单详情
     */
    WorkOrder getWorkOrderDetail(Long orderId);

    /**
     * 查询工单操作日志列表
     */
    List<WorkOrderLog> getWorkOrderLogs(Long orderId);

    /**
     * 派单
     */
    boolean dispatchOrder(Long orderId, Long handlerId, String remarks, Long operUserId, String operUserName);

    /**
     * 批量派单（支持多人）
     */
    boolean batchDispatchOrder(Long orderId, List<Long> handlerIds, String remarks, Long operUserId, String operUserName);

    /**
     * 核查
     */
    boolean verifyOrder(Long orderId, String handleResult, String solution, Long operUserId, String operUserName);

    /**
     * 处理
     */
    boolean processOrder(Long orderId, String handleResult, String solution, Long operUserId, String operUserName);

    /**
     * 完成/提交验收
     */
    boolean completeOrder(Long orderId, String result, Long operUserId, String operUserName);

    /**
     * 取消工单
     */
    boolean cancelOrder(Long orderId, Long operUserId, String operUserName);

    /**
     * 验收通过/结案（status 5→6），同步联动隐患状态为"已整改"
     */
    boolean closeOrder(Long orderId, String result, Long operUserId, String operUserName);

    /**
     * 从隐患创建工单
     * @param hazardId 隐患ID
     * @param hazardNo 隐患编号
     * @param hazardDesc 隐患描述
     * @param equipmentId 设备ID
     * @param hazardLevel 隐患等级
     * @param hazardImages 隐患图片
     * @param planFinishTime 计划完成时间
     * @return 工单ID
     */
    Long createWorkOrderFromHazard(String hazardId, String hazardNo, String hazardDesc, String equipmentId,
                                    String hazardLevel, String hazardImages, Date planFinishTime);
}
