package org.eco.als.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.eco.als.domain.bo.AirParamterBo;
import org.eco.als.domain.vo.AirParamterVo;
import org.eco.als.service.IAirParamterService;
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/airParamter")
public class AirParamterController extends BaseController {
    @Resource
    private IAirParamterService airParamterService;

    /**
     * 查询飞机系统参数管理列表
     */
    @SaCheckPermission("als:airParamter:list")
    @GetMapping("/list")
    public CommonResult<PageResult<AirParamterVo>> list(AirParamterBo airParamterBo) {
        return CommonResult.success(airParamterService.selectPage(airParamterBo));
    }

    /**
     * 获取飞机系统参数管理详细信息
     */
    @SaCheckPermission("als:airParamter:query")
    @GetMapping(value = "/{id}")
    public CommonResult<AirParamterVo> getInfo(@PathVariable Long id) {
        return CommonResult.success(airParamterService.selectById(id));
    }

    /**
     * 新增飞机系统参数管理
     */
    @SaCheckPermission("als:airParamter:add")
    @Log(title = "飞机系统参数管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public CommonResult<Void> add(@Validated @RequestBody AirParamterBo airParamterBo) {
        boolean inserted = airParamterService.insert(airParamterBo);
        if (!inserted) {
            return CommonResult.fail("新增飞机系统参数管理记录失败！");
        }
        return CommonResult.success();
    }

    /**
     * 修改飞机系统参数管理
     */
    @SaCheckPermission("als:airParamter:edit")
    @Log(title = "飞机系统参数管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public CommonResult<Void> edit(@Validated @RequestBody AirParamterBo airParamterBo) {
        boolean updated = airParamterService.update(airParamterBo);
        if (!updated) {
            return CommonResult.fail("修改飞机系统参数管理记录失败!");
        }
        return CommonResult.success();
    }

    /**
     * 删除飞机系统参数管理
     */
    @SaCheckPermission("als:airParamter:remove")
    @Log(title = "飞机系统参数管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult<Void> remove(@PathVariable Long[] ids) {
        boolean deleted = airParamterService.deleteByIds(ids);
        if (!deleted) {
            return CommonResult.fail("删除飞机系统参数管理记录失败!");
        }
        return CommonResult.success();
    }
}
