package cn.iocoder.yudao.module.configure.controller.admin.deviceenvtype;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.configure.controller.admin.deviceenvtype.vo.DeviceEnvTypeCreateReqVO;
import cn.iocoder.yudao.module.configure.controller.admin.deviceenvtype.vo.DeviceEnvTypeRespVO;
import cn.iocoder.yudao.module.configure.controller.admin.deviceenvtype.vo.DeviceEnvTypeUpdateReqVO;
import cn.iocoder.yudao.module.configure.convert.deviceenvtype.DeviceEnvTypeConvert;
import cn.iocoder.yudao.module.configure.dal.dataobject.deviceenvtype.DeviceEnvTypeDO;
import cn.iocoder.yudao.module.configure.service.deviceenvtype.DeviceEnvTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 小程序设备环境类型配置")
@RestController
@RequestMapping("/configure/device-env-type")
@Validated
public class DeviceEnvTypeController {

    @Resource
    private DeviceEnvTypeService deviceEnvTypeService;

    @PostMapping("/create")
    @ApiOperation("创建小程序设备环境类型配置")
    @PreAuthorize("@ss.hasPermission('configure:device-env-type:create')")
    public CommonResult<Long> createDeviceEnvType(@Valid @RequestBody DeviceEnvTypeCreateReqVO createReqVO) {
        return success(deviceEnvTypeService.createDeviceEnvType(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新小程序设备环境类型配置")
    @PreAuthorize("@ss.hasPermission('configure:device-env-type:update')")
    public CommonResult<Boolean> updateDeviceEnvType(@Valid @RequestBody DeviceEnvTypeUpdateReqVO updateReqVO) {
        deviceEnvTypeService.updateDeviceEnvType(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除小程序设备环境类型配置")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('configure:device-env-type:delete')")
    public CommonResult<Boolean> deleteDeviceEnvType(@RequestParam("id") Long id) {
        deviceEnvTypeService.deleteDeviceEnvType(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得小程序设备环境类型配置")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('configure:device-env-type:query')")
    public CommonResult<DeviceEnvTypeRespVO> getDeviceEnvType(@RequestParam("id") Long id) {
        DeviceEnvTypeDO deviceEnvType = deviceEnvTypeService.getDeviceEnvType(id);
        return success(DeviceEnvTypeConvert.INSTANCE.convert(deviceEnvType));
    }

}
