package com.multictrl.modules.business.controller;

import com.multictrl.common.annotation.ApiOrder;
import com.multictrl.common.annotation.LogOperation;
import com.multictrl.common.utils.Result;
import com.multictrl.common.validator.ValidatorUtils;
import com.multictrl.common.validator.group.AddGroup;
import com.multictrl.common.validator.group.DefaultGroup;
import com.multictrl.common.validator.group.UpdateGroup;
import com.multictrl.modules.business.dto.AiWarningDTO;
import com.multictrl.modules.business.service.AiWarningService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * AI识别预警
 *
 * @author Sdy
 * @since 1.0.0 2026-06-18
 */
@RestController
@RequestMapping("business/ai/warning")
@Tag(name = "AI识别预警")
@ApiOrder(26)
@RequiredArgsConstructor
public class AiWarningController {
    private final AiWarningService aiWarningService;

    @PostMapping
    @Operation(summary = "设置ai预警")
    @LogOperation("设置ai预警")
    @RequiresPermissions("bus:ai:warning:save")
    public Result<Object> save(@RequestBody AiWarningDTO dto) {
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class);
        aiWarningService.save(dto);

        return new Result<>();
    }

    @PutMapping
    @Operation(summary = "修改ai预警")
    @LogOperation("修改ai预警")
    @RequiresPermissions("bus:ai:warning:update")
    public Result<Object> update(@RequestBody AiWarningDTO dto) {
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class);
        aiWarningService.update(dto);

        return new Result<>();
    }

    @GetMapping
    @Operation(summary = "获取预警信息")
    @RequiresPermissions("bus:ai:warning:get")
    public Result<List<AiWarningDTO>> get() {
        Map<String, Object> map = new HashMap<>();
        map.put("status", "1");
        List<AiWarningDTO> list = aiWarningService.list(map);

        return new Result<List<AiWarningDTO>>().ok(list);
    }
}
