package com.multictrl.modules.business.controller;

import com.multictrl.common.annotation.ApiOrder;
import com.multictrl.common.annotation.LogOperation;
import com.multictrl.common.constant.Constant;
import com.multictrl.common.page.PageData;
import com.multictrl.common.utils.Result;
import com.multictrl.common.validator.AssertUtils;
import com.multictrl.modules.business.dto.FlightTaskDTO;
import com.multictrl.modules.business.service.FlightTaskService;
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 io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;

import java.util.Map;

/**
 * 飞行架次
 *
 * @author Sdy
 * @since 1.0.0 2026-05-02
 */
@RestController
@RequestMapping("business/task")
@Tag(name = "飞行架次")
@ApiOrder(7)
@RequiredArgsConstructor
public class FlightTaskController {
    private final FlightTaskService flightTaskService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @Parameters({
            @Parameter(name = Constant.PAGE, description = "当前页码，从1开始"),
            @Parameter(name = Constant.LIMIT, description = "每页显示记录数")
    })
    @RequiresPermissions("business:task:page")
    public Result<PageData<FlightTaskDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
        PageData<FlightTaskDTO> page = flightTaskService.page(params);

        return new Result<PageData<FlightTaskDTO>>().ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @RequiresPermissions("business:task:info")
    public Result<FlightTaskDTO> get(@PathVariable("id") Long id) {
        FlightTaskDTO data = flightTaskService.get(id);

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

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

        return new Result<>();
    }
}
