package com.xindazhou.vehicle.controller.admin.vehicle;

import com.xindazhou.framework.common.pojo.CommonResult;
import com.xindazhou.framework.common.pojo.PageResult;
import com.xindazhou.vehicle.controller.admin.vehicle.vo.VehicleTheftPageReqVO;
import com.xindazhou.vehicle.controller.admin.vehicle.vo.VehicleTheftRespVO;
import com.xindazhou.vehicle.service.theft.VehicleTheftService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.xindazhou.framework.common.pojo.CommonResult.success;

/**
 * 管理后台 - 失窃监控 Controller
 *
 * @author xindazhou
 */
@Tag(name = "管理后台 - 失窃监控")
@RestController
@RequestMapping("/admin/vehicle/theft")
@Validated
public class VehicleTheftController {

    @Resource
    private VehicleTheftService theftService;

    @GetMapping("/page")
    @Operation(summary = "获得失窃监控分页")
    @PreAuthorize("@ss.hasPermission('vehicle:theft:query')")
    public CommonResult<PageResult<VehicleTheftRespVO>> getVehicleTheftPage(@Valid VehicleTheftPageReqVO pageReqVO) {
        PageResult<VehicleTheftRespVO> pageResult = theftService.getVehicleTheftPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/get")
    @Operation(summary = "获得失窃监控")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('vehicle:theft:query')")
    public CommonResult<VehicleTheftRespVO> getVehicleTheft(@RequestParam("id") Long id) {
        VehicleTheftRespVO theft = theftService.getVehicleTheft(id);
        return success(theft);
    }

    @PostMapping("/markNormal")
    @Operation(summary = "标记车辆为正常")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('vehicle:theft:update')")
    public CommonResult<Boolean> markVehicleNormal(@RequestParam("id") Long id) {
        theftService.markVehicleNormal(id);
        return success(true);
    }

}
