package com.emergency.avenue.storage.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.emergency.avenue.common.core.util.R;
import com.emergency.avenue.common.log.annotation.SysLog;
import com.emergency.avenue.storage.api.entity.InTransitVehicleInfo;
import com.emergency.avenue.storage.service.InTransitVehicleInfoService;
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("/inTransitVehicle")
@Tag(description = "inTransitVehicle", name = "在途车辆信息管理")
public class InTransitVehicleInfoController {

	private final InTransitVehicleInfoService inTransitVehicleInfoService;
	/**
	 * 获取在途车辆信息管理列表
	 * @return 在途车辆信息管理列表
	 */
	@GetMapping("/list")
	public R<List<InTransitVehicleInfo>> listPosts() {
		return R.ok(inTransitVehicleInfoService.list(Wrappers.emptyWrapper()));
	}

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param inTransitVehicleInfo 在途车辆信息管理表
	 * @return
	 */
	@Operation(description = "分页查询", summary = "分页查询")
	@GetMapping("/page")
	public R getInTransitVehicleInfoPage(Page page, InTransitVehicleInfo inTransitVehicleInfo) {
		return R.ok(inTransitVehicleInfoService.page(page, Wrappers.query(inTransitVehicleInfo)));
	}

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

	/**
	 * 新增在途车辆信息管理表
	 * @param inTransitVehicleInfo 在途车辆信息管理表
	 * @return R
	 */
	@Operation(description = "新增在途车辆信息管理表", summary = "新增在途车辆信息管理表")
	@SysLog("新增在途车辆信息管理表")
	@PostMapping
	public R save(@RequestBody InTransitVehicleInfo inTransitVehicleInfo) {
		return R.ok(inTransitVehicleInfoService.save(inTransitVehicleInfo));
	}

	/**
	 * 修改在途车辆信息管理表
	 * @param inTransitVehicleInfo 在途车辆信息管理表
	 * @return R
	 */
	@Operation(description = "修改在途车辆信息管理表", summary = "修改在途车辆信息管理表")
	@SysLog("修改在途车辆信息管理表")
	@PutMapping
	public R updateById(@RequestBody InTransitVehicleInfo inTransitVehicleInfo) {
		return R.ok(inTransitVehicleInfoService.updateById(inTransitVehicleInfo));
	}

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