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.VehicleGuidePageReqVO;
import com.xindazhou.vehicle.controller.admin.vehicle.vo.VehicleGuideRespVO;
import com.xindazhou.vehicle.controller.admin.vehicle.vo.VehicleGuideSaveReqVO;
import com.xindazhou.vehicle.service.guide.VehicleGuideService;
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 java.util.Collection;

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

/**
 * 管理后台 - 使用指南 Controller
 *
 * @author xindazhou
 */
@Tag(name = "管理后台 - 使用指南与支持")
@RestController
@RequestMapping("/admin/vehicle/guide")
@Validated
public class VehicleGuideController {

    @Resource
    private VehicleGuideService vehicleGuideService;

    @GetMapping("/page")
    @Operation(summary = "获得使用指南分页")
    @PreAuthorize("@ss.hasPermission('vehicle:guide:query')")
    public CommonResult<PageResult<VehicleGuideRespVO>> getVehicleGuidePage(@Valid VehicleGuidePageReqVO pageReqVO) {
        PageResult<VehicleGuideRespVO> pageResult = vehicleGuideService.getVehicleGuidePage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/get")
    @Operation(summary = "获得使用指南")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('vehicle:guide:query')")
    public CommonResult<VehicleGuideRespVO> getVehicleGuide(@RequestParam("id") Long id) {
        VehicleGuideRespVO guide = vehicleGuideService.getVehicleGuide(id);
        return success(guide);
    }

    @PostMapping("/create")
    @Operation(summary = "创建使用指南")
    @PreAuthorize("@ss.hasPermission('vehicle:guide:create')")
    public CommonResult<Long> createVehicleGuide(@Valid @RequestBody VehicleGuideSaveReqVO createReqVO) {
        return success(vehicleGuideService.createVehicleGuide(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新使用指南")
    @PreAuthorize("@ss.hasPermission('vehicle:guide:update')")
    public CommonResult<Boolean> updateVehicleGuide(@Valid @RequestBody VehicleGuideSaveReqVO updateReqVO) {
        vehicleGuideService.updateVehicleGuide(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除使用指南")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('vehicle:guide:delete')")
    public CommonResult<Boolean> deleteVehicleGuide(@RequestParam("id") Long id) {
        vehicleGuideService.deleteVehicleGuide(id);
        return success(true);
    }

    @DeleteMapping("/batchDelete")
    @Operation(summary = "批量删除使用指南")
    @PreAuthorize("@ss.hasPermission('vehicle:guide:delete')")
    public CommonResult<Boolean> batchDeleteVehicleGuide(@RequestParam("ids") Collection<Long> ids) {
        vehicleGuideService.batchDeleteVehicleGuide(ids);
        return success(true);
    }

    @PostMapping("/onShelf")
    @Operation(summary = "上架使用指南")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('vehicle:guide:update')")
    public CommonResult<Boolean> onShelfVehicleGuide(@RequestParam("id") Long id) {
        vehicleGuideService.onShelfVehicleGuide(id);
        return success(true);
    }

    @PostMapping("/batchDisplay")
    @Operation(summary = "批量显示/不显示使用指南")
    @PreAuthorize("@ss.hasPermission('vehicle:guide:update')")
    public CommonResult<Boolean> batchDisplayVehicleGuide(@RequestParam("ids") Collection<Long> ids,
                                                           @RequestParam("isDisplay") Integer isDisplay) {
        vehicleGuideService.batchDisplayVehicleGuide(ids, isDisplay);
        return success(true);
    }

}

