package org.eco.als.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.eco.als.domain.bo.WarningResultBo;
import org.eco.als.domain.vo.WarningResultVo;
import org.eco.als.service.IWarningResultService;
import org.eco.common.core.core.domain.CommonResult;
import org.eco.common.core.core.page.PageResult;
import org.eco.common.log.annotation.Log;
import org.eco.common.log.enums.BusinessType;
import org.eco.common.web.annotation.RepeatSubmit;
import org.eco.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 警告结果Controller
 *
 * @author wgk
 * @date 2025-02-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/als/warningResult")
public class WarningResultController extends BaseController {
    @Resource
    private IWarningResultService warningResultService;

    /**
     * 查询警告结果列表
     */
    @SaCheckPermission("als:warningResult:list")
    @GetMapping("/list")
    public CommonResult<PageResult<WarningResultVo>> list(WarningResultBo warningResultBo) {
        return CommonResult.success(warningResultService.selectPage(warningResultBo));
    }

    /**
     * 获取警告结果详细信息
     */
    @SaCheckPermission("als:warningResult:query")
    @GetMapping(value = "/{id}")
    public CommonResult<WarningResultVo> getInfo(@PathVariable Long id) {
        return CommonResult.success(warningResultService.selectById(id));
    }

    /**
     * 新增警告结果
     */
    @SaCheckPermission("als:warningResult:add")
    @Log(title = "警告结果", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public CommonResult<Void> add(@Validated @RequestBody WarningResultBo warningResultBo) {
        boolean inserted = warningResultService.insert(warningResultBo);
        if (!inserted) {
            return CommonResult.fail("新增警告结果记录失败！");
        }
        return CommonResult.success();
    }

    /**
     * 修改警告结果
     */
    @SaCheckPermission("als:warningResult:edit")
    @Log(title = "警告结果", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public CommonResult<Void> edit(@Validated @RequestBody WarningResultBo warningResultBo) {
        boolean updated = warningResultService.update(warningResultBo);
        if (!updated) {
            return CommonResult.fail("修改警告结果记录失败!");
        }
        return CommonResult.success();
    }

    /**
     * 删除警告结果
     */
    @SaCheckPermission("als:warningResult:remove")
    @Log(title = "警告结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult<Void> remove(@PathVariable Long[] ids) {
        boolean deleted = warningResultService.deleteByIds(ids);
        if (!deleted) {
            return CommonResult.fail("删除警告结果记录失败!");
        }
        return CommonResult.success();
    }
}
