package com.hotwj.platform.securityManagement.violationInfo.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.hotwj.platform.securityManagement.violationInfo.domain.bo.HotViolationAuditBo;
import com.hotwj.platform.securityManagement.violationInfo.domain.bo.HotViolationInfoBo;
import com.hotwj.platform.securityManagement.violationInfo.domain.vo.HotViolationInfoVo;
import com.hotwj.platform.securityManagement.violationInfo.service.IHotViolationInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 违规信息
 *
 * @author shihongwei
 * @date 2026-01-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/securityManagement/violationInfo")
@Tag(name = "违规信息", description = "违规信息管理")
public class HotViolationInfoController extends BaseController {

    private final IHotViolationInfoService hotViolationInfoService;

    /**
     * 查询违规信息列表
     */
    //@SaCheckPermission("securityManagement:violationInfo:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询违规信息列表")
    public TableDataInfo<HotViolationInfoVo> list(HotViolationInfoBo bo, PageQuery pageQuery) {
        return hotViolationInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出违规信息列表
     */
    //@SaCheckPermission("securityManagement:violationInfo:export")
    @Log(title = "违规信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出违规信息列表")
    public void export(HotViolationInfoBo bo, HttpServletResponse response) {
        List<HotViolationInfoVo> list = hotViolationInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "违规信息", HotViolationInfoVo.class, response);
    }

    /**
     * 审核并完成违规处理（司机或企业均可办理）
     */
    //@SaCheckPermission("securityManagement:violationInfo:edit")
    @PostMapping("/audit")
    @Operation(summary = "审核并完成违规处理")
    public R<Boolean> audit(@Validated @RequestBody HotViolationAuditBo bo) {
        return R.ok(hotViolationInfoService.auditAndComplete(bo.getTaskId(), bo.getProcessStatus(), bo.getDisposalResult(), bo.getInterviewedSignatureImage(), bo.getPartySignatureImage()));
    }

    /**
     * 获取违规信息详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("securityManagement:violationInfo:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取违规信息详细信息")
    public R<HotViolationInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                         @Parameter(name = "id", description = "主键", required = true, example = "1")
                                         @PathVariable Long id) {
        return R.ok(hotViolationInfoService.queryById(id));
    }

    /**
     * 新增违规信息
     */
    //@SaCheckPermission("securityManagement:violationInfo:add")
    @Log(title = "违规信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增违规信息")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotViolationInfoBo bo) {
        return toAjax(hotViolationInfoService.insertByBo(bo));
    }

    /**
     * 修改违规信息
     */
    //@SaCheckPermission("securityManagement:violationInfo:edit")
    @Log(title = "违规信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改违规信息")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotViolationInfoBo bo) {
        return toAjax(hotViolationInfoService.updateByBo(bo));
    }

    /**
     * 删除违规信息
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("securityManagement:violationInfo:remove")
    @Log(title = "违规信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除违规信息")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @Parameter(name = "ids", description = "主键串", required = true, example = "1,2,3")
                          @PathVariable Long[] ids) {
        return toAjax(hotViolationInfoService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 驾驶员查询违规列表（待办/已办）
     */
    @GetMapping("/driver/list")
    @Operation(summary = "驾驶员查询违规列表")
    public TableDataInfo<HotViolationInfoVo> driverList(HotViolationInfoBo bo, PageQuery pageQuery) {
        return hotViolationInfoService.queryDriverList(bo, pageQuery);
    }
}
