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.VehicleAuthPageReqVO;
import com.xindazhou.vehicle.controller.admin.vehicle.vo.VehicleAuthSaveReqVO;
import com.xindazhou.vehicle.controller.admin.vehicle.vo.VehicleAuthRespVO;
import com.xindazhou.vehicle.service.auth.VehicleAuthService;
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/auth")
@Validated
public class VehicleAuthController {

    @Resource
    private VehicleAuthService authService;

    @GetMapping("/page")
    @Operation(summary = "获得车辆授权设置分页")
    @PreAuthorize("@ss.hasPermission('vehicle:auth:query')")
    public CommonResult<PageResult<VehicleAuthRespVO>> getVehicleAuthPage(@Valid VehicleAuthPageReqVO pageReqVO) {
        PageResult<VehicleAuthRespVO> pageResult = authService.getVehicleAuthPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/get")
    @Operation(summary = "获得车辆授权设置")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('vehicle:auth:query')")
    public CommonResult<VehicleAuthRespVO> getVehicleAuth(@RequestParam("id") Long id) {
        VehicleAuthRespVO auth = authService.getVehicleAuth(id);
        return success(auth);
    }

    @PostMapping("/create")
    @Operation(summary = "创建车辆授权设置")
    @PreAuthorize("@ss.hasPermission('vehicle:auth:create')")
    public CommonResult<Long> createVehicleAuth(@Valid @RequestBody VehicleAuthSaveReqVO createReqVO) {
        return success(authService.createVehicleAuth(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新车辆授权设置")
    @PreAuthorize("@ss.hasPermission('vehicle:auth:update')")
    public CommonResult<Boolean> updateVehicleAuth(@Valid @RequestBody VehicleAuthSaveReqVO updateReqVO) {
        authService.updateVehicleAuth(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除车辆授权设置")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('vehicle:auth:delete')")
    public CommonResult<Boolean> deleteVehicleAuth(@RequestParam("id") Long id) {
        authService.deleteVehicleAuth(id);
        return success(true);
    }

}
