package com.aircraft.modules.aircraft.controller;


import com.aircraft.modules.aircraft.domain.AircraftDevice;
import com.aircraft.modules.aircraft.domain.dto.AircraftDevicePageDTO;
import com.aircraft.modules.aircraft.domain.vo.AircraftDevicePageVO;
import com.aircraft.modules.aircraft.service.AircraftDeviceService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 飞行器设备表 前端控制器
 * </p>
 *
 * @author cli
 * @since 2025-07-11
 */
@Api(tags = "飞行器设备管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/aircraft/device")
public class AircraftDeviceController {


    private final AircraftDeviceService aircraftDeviceService;

    /**
     * 分页查询飞行器设备
     */
    @ApiOperation("分页查询飞行器设备")
    @GetMapping("/page")
    public ResponseEntity<IPage<AircraftDevicePageVO>> page(AircraftDevicePageDTO dto, Page page) {
        return ResponseEntity.ok(aircraftDeviceService.page(dto, page));
    }

    /**
     * 新增飞行器设备
     */
    @ApiOperation("新增飞行器设备")
    @PostMapping
    public ResponseEntity<Object> create(@RequestBody @Validated AircraftDevice aircraftDevice) {
        aircraftDeviceService.create(aircraftDevice);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 编辑飞行器设备
     */
    @ApiOperation("编辑飞行器设备")
    @PutMapping
    public ResponseEntity<Object> update(@RequestBody @Validated(AircraftDevice.Update.class) AircraftDevice aircraftDevice) {
        aircraftDeviceService.update(aircraftDevice);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 删除飞行器设备
     */
    @ApiOperation("删除飞行器设备")
    @DeleteMapping("/{id}")
    public ResponseEntity<Object> deleteById(@PathVariable Long id) {
        aircraftDeviceService.deleteById(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 根据ID查询飞行器设备
     */
    @ApiOperation("根据ID查询飞行器设备")
    @GetMapping("/{id}")
    public ResponseEntity<Object> findById(@PathVariable Long id) {
        return ResponseEntity.ok(aircraftDeviceService.findById(id));
    }

}

