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.AssertUtils;
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.WeatherNoflyDTO;
import com.multictrl.modules.business.service.WeatherNoflyService;
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.*;

/**
 * 天气阻飞
 *
 * @author Sdy
 * @since 1.0.0 2026-06-15
 */
@RestController
@RequestMapping("business/weathernofly")
@Tag(name = "天气阻飞")
@ApiOrder(24)
@RequiredArgsConstructor
public class WeatherNoflyController {
    private final WeatherNoflyService weatherNoflyService;

    @GetMapping("{dockSn}")
    @Operation(summary = "信息")
    @RequiresPermissions("bus:weathernofly:info")
    public Result<WeatherNoflyDTO> get(@PathVariable String dockSn) {
        WeatherNoflyDTO data = weatherNoflyService.getInfoByDockSn(dockSn);

        return new Result<WeatherNoflyDTO>().ok(data);
    }

    @PostMapping
    @Operation(summary = "保存")
    @LogOperation("保存")
    @RequiresPermissions("bus:weathernofly:save")
    public Result<Object> save(@RequestBody WeatherNoflyDTO dto) {
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class);
        weatherNoflyService.addWeatherNofly(dto);

        return new Result<>();
    }

    @PutMapping
    @Operation(summary = "修改")
    @LogOperation("修改")
    @RequiresPermissions("bus:weathernofly:update")
    public Result<Object> update(@RequestBody WeatherNoflyDTO dto) {
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class);
        weatherNoflyService.update(dto);

        return new Result<>();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @LogOperation("删除")
    @RequiresPermissions("bus:weathernofly:delete")
    public Result<Object> delete(@RequestBody Long[] ids) {
        //效验数据
        AssertUtils.isArrayEmpty(ids, "id");
        weatherNoflyService.delete(ids);

        return new Result<>();
    }

}
