package com.aircraft.modules.aircraft.controller;


import com.aircraft.modules.aircraft.domain.AircraftInsurance;
import com.aircraft.modules.aircraft.service.AircraftInsuranceService;
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/insurance")
public class AircraftInsuranceController {

    private final AircraftInsuranceService aircraftInsuranceService;

    /**
     * 分页查询飞行器保险
     */
    @ApiOperation("分页查询飞行器保险")
    @GetMapping("/page")
    public ResponseEntity<IPage<AircraftInsurance>> page(Long aircraftId,
                                                         Page page) {
        return ResponseEntity.ok(aircraftInsuranceService.page(aircraftId, page));
    }

    /**
     * 新增飞行器保险
     */
    @ApiOperation("新增飞行器保险")
    @PostMapping
    public ResponseEntity<Object> create(@RequestBody @Validated AircraftInsurance aircraftInsurance) {
        aircraftInsuranceService.create(aircraftInsurance);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 编辑飞行器保险
     */
    @ApiOperation("编辑飞行器保险")
    @PutMapping
    public ResponseEntity<Object> update(@RequestBody @Validated(AircraftInsurance.Update.class) AircraftInsurance aircraftInsurance) {
        aircraftInsuranceService.update(aircraftInsurance);
        return new ResponseEntity<>(HttpStatus.OK);
    }

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

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

}

