package com.emergency.avenue.storage.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.emergency.avenue.common.core.util.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.emergency.avenue.common.log.annotation.SysLog;
import com.emergency.avenue.common.security.annotation.Inner;
import com.emergency.avenue.storage.api.entity.VehicleInfo;
import com.emergency.avenue.storage.service.VehicleInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/vehicle")
@Tag(description = "vehicle", name = "车辆信息管理")
public class VehicleInfoController {
	private final VehicleInfoService vehicleInfoService;

	/**
	 * 获取车辆列表
	 * @return 车辆列表
	 */
	@GetMapping("/list")
	@Inner(value = false)
	public R<List<VehicleInfo>> listPosts() {
		return R.ok(vehicleInfoService.list(Wrappers.emptyWrapper()));
	}

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param vehicleInfo 车辆信息表
	 * @return
	 */
	@Operation(description = "分页查询", summary = "分页查询")
	@GetMapping("/page")
	public R getVehicleInfoPage(Page page, VehicleInfo vehicleInfo) {
		return R.ok(vehicleInfoService.page(page, Wrappers.query(vehicleInfo)));
	}

	/**
	 * 通过id查询车辆信息表
	 * @param vehicleId id
	 * @return R
	 */
	@Operation(description = "通过id查询", summary = "通过id查询")
	@GetMapping("/{vehicleId}")
	public R getById(@PathVariable("vehicleId") Long vehicleId) {
		return R.ok(vehicleInfoService.getById(vehicleId));
	}

	/**
	 * 新增车辆信息表
	 * @param vehicleInfo 车辆信息表
	 * @return R
	 */
	@Operation(description = "新增车辆信息表", summary = "新增车辆信息表")
	@SysLog("新增车辆信息表")
	@PostMapping
	public R save(@RequestBody VehicleInfo vehicleInfo) {
		return R.ok(vehicleInfoService.save(vehicleInfo));
	}

	/**
	 * 修改车辆信息表
	 * @param vehicleInfo 车辆信息表
	 * @return R
	 */
	@Operation(description = "修改车辆信息表", summary = "修改车辆信息表")
	@SysLog("修改车辆信息表")
	@PutMapping
	public R updateById(@RequestBody VehicleInfo vehicleInfo) {
		return R.ok(vehicleInfoService.updateById(vehicleInfo));
	}

	/**
	 * 通过id删除车辆信息表
	 * @param vehicleId id
	 * @return R
	 */
	@Operation(description = "通过id删除车辆信息表", summary = "通过id删除车辆信息表")
	@SysLog("通过id删除车辆信息表")
	@DeleteMapping("/{vehicleId}")
	public R removeById(@PathVariable Long vehicleId) {
		return R.ok(vehicleInfoService.removeById(vehicleId));
	}
}
