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.VehicleSoundPageReqVO;
import com.xindazhou.vehicle.controller.admin.vehicle.vo.VehicleSoundSaveReqVO;
import com.xindazhou.vehicle.controller.admin.vehicle.vo.VehicleSoundRespVO;
import com.xindazhou.vehicle.service.sound.VehicleSoundService;
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;

/**
 * 管理后台 - APP音效管理 Controller
 *
 * @author xindazhou
 */
@Tag(name = "管理后台 - APP音效管理")
@RestController
@RequestMapping("/admin/vehicle/sound")
@Validated
public class VehicleSoundController {

    @Resource
    private VehicleSoundService soundService;

    @GetMapping("/page")
    @Operation(summary = "获得APP音效管理分页")
    @PreAuthorize("@ss.hasPermission('vehicle:sound:query')")
    public CommonResult<PageResult<VehicleSoundRespVO>> getVehicleSoundPage(@Valid VehicleSoundPageReqVO pageReqVO) {
        PageResult<VehicleSoundRespVO> pageResult = soundService.getVehicleSoundPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/get")
    @Operation(summary = "获得APP音效管理")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('vehicle:sound:query')")
    public CommonResult<VehicleSoundRespVO> getVehicleSound(@RequestParam("id") Long id) {
        VehicleSoundRespVO sound = soundService.getVehicleSound(id);
        return success(sound);
    }

    @PostMapping("/create")
    @Operation(summary = "创建APP音效管理")
    @PreAuthorize("@ss.hasPermission('vehicle:sound:create')")
    public CommonResult<Long> createVehicleSound(@Valid @RequestBody VehicleSoundSaveReqVO createReqVO) {
        return success(soundService.createVehicleSound(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新APP音效管理")
    @PreAuthorize("@ss.hasPermission('vehicle:sound:update')")
    public CommonResult<Boolean> updateVehicleSound(@Valid @RequestBody VehicleSoundSaveReqVO updateReqVO) {
        soundService.updateVehicleSound(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除APP音效管理")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('vehicle:sound:delete')")
    public CommonResult<Boolean> deleteVehicleSound(@RequestParam("id") Long id) {
        soundService.deleteVehicleSound(id);
        return success(true);
    }

}
