package com.zksy.web.controller.dispatch;

import com.zksy.common.annotation.Anonymous;
import com.zksy.common.annotation.Log;
import com.zksy.common.core.domain.AjaxResult;
import com.zksy.common.enums.BusinessType;
import com.zksy.dispatch.domain.DisEventAssess;
import com.zksy.dispatch.dto.DisEventAssessSaveDTO;
import com.zksy.dispatch.service.DisEventAssessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 应急事件事后评估接口（评估挂靠统一事件主表）
 * 事件列表（已解除/已关闭） -> 四维评分评估 -> 生成报告/录入案例库
 */
@Slf4j
@RestController
@RequestMapping("/api/dispatch/assess")
@Api(tags = "应急事件事后评估")
public class DisEventAssessController {

    @Autowired
    private DisEventAssessService service;

    @GetMapping("/findByEventId")
    @ApiOperation("查询单个事件的评估记录（无则返回 null）")
    @Anonymous
    public AjaxResult findByEventId(@RequestParam Long eventId) {
        return AjaxResult.success(service.findByEventId(eventId));
    }

    @GetMapping("/listByEventIds")
    @ApiOperation("批量查询事件的评估记录（列表标记已评估/待评估）")
    @Anonymous
    public AjaxResult listByEventIds(@RequestParam List<Long> eventIds) {
        return AjaxResult.success(service.listByEventIds(eventIds));
    }

    @PostMapping("/save")
    @ApiOperation("保存/更新事件评估（有则更新，无则新增；自动计算综合分与等级）")
    @Log(title = "保存事件事后评估", businessType = BusinessType.INSERT)
    public AjaxResult save(@RequestBody DisEventAssessSaveDTO dto) {
        DisEventAssess saved = service.saveAssess(dto);
        return AjaxResult.success("评估保存成功", saved);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除事件的评估记录（重新评估）")
    @Log(title = "删除事件事后评估", businessType = BusinessType.DELETE)
    public AjaxResult delete(@RequestParam Long eventId) {
        service.deleteByEventId(eventId);
        return AjaxResult.success("评估已重置");
    }
}
