package cn.iocoder.yudao.module.system.controller.admin.biz;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ManufacturerPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ManufacturerRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ManufacturerSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ManufacturerDO;
import cn.iocoder.yudao.module.system.service.biz.ManufacturerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
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;

/**
 * @Author: jinyd
 * @CreateTime: 2024/10/15  11:23
 * @Description:
 * @Version: 4.0
 */


@Tag(name = "管理后台 - 设备厂商")
@RestController
@RequestMapping("/device/manufacturer")
@Validated
public class ManufacturerController {

    @Resource
    private ManufacturerService manufacturerService;

    @PostMapping("/create")
    @Operation(summary = "创建设备厂商")
    @PreAuthorize("@ss.hasPermission('device:manufacturer:create')")
    public CommonResult<Long> createManufacturer(@Valid @RequestBody ManufacturerSaveReqVO createReqVO) {
        return success(manufacturerService.createManufacturer(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新设备厂商")
    @PreAuthorize("@ss.hasPermission('device:manufacturer:update')")
    public CommonResult<Boolean> updateManufacturer(@Valid @RequestBody ManufacturerSaveReqVO updateReqVO) {
        manufacturerService.updateManufacturer(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除设备厂商")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('device:manufacturer:delete')")
    public CommonResult<Boolean> deleteManufacturer(@RequestParam("id") Long id) {
        manufacturerService.deleteManufacturer(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得设备厂商")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('device:manufacturer:query')")
    public CommonResult<ManufacturerRespVO> getManufacturer(@RequestParam("id") Long id) {
        ManufacturerDO manufacturer = manufacturerService.getManufacturer(id);
        return success(BeanUtils.toBean(manufacturer, ManufacturerRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得设备厂商分页")
//    @PreAuthorize("@ss.hasPermission('device:manufacturer:query')")
    public CommonResult<PageResult<ManufacturerRespVO>> getManufacturerPage(@Valid ManufacturerPageReqVO pageReqVO) {
        PageResult<ManufacturerDO> pageResult = manufacturerService.getManufacturerPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ManufacturerRespVO.class));
    }



}
