package cn.iocoder.yudao.module.museum.controller.admin.museummodel;

import cn.hutool.core.collection.CollUtil;
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.museum.controller.admin.museummodel.vo.MuseummodelPageReqVO;
import cn.iocoder.yudao.module.museum.controller.admin.museummodel.vo.MuseummodelRespVO;
import cn.iocoder.yudao.module.museum.controller.admin.museummodel.vo.MuseummodelSaveVO;
import cn.iocoder.yudao.module.museum.dal.database.museummodel.MuseummodelDO;
import cn.iocoder.yudao.module.museum.service.museummodel.MuseummodelService;
import io.swagger.v3.oas.annotations.Operation;
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 java.util.Map;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;

@Tag(name = "博物馆-模型库")
@RestController
@RequestMapping("/museum/model")
@Validated
public class MuseummodelController {

    @Resource
    private MuseummodelService museumModelService;

    @PostMapping("/create")
    @Operation(summary = "新增模型")
    public Integer createMuseumModel(@RequestBody MuseummodelSaveVO saveVO) {
        return museumModelService.createMuseumModel(saveVO);
    }

    @PutMapping("/update")
    @Operation(summary = "更新模型")
    public CommonResult<Boolean> updateMuseumModel(@RequestBody MuseummodelSaveVO saveVO) {
        museumModelService.updateMuseumModel(saveVO);
        return CommonResult.success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除模型")
    public CommonResult<Boolean> deleteMuseumModel(@RequestParam("id") Integer id) {
        museumModelService.deleteMuseumModel(id);
        return CommonResult.success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "查找模型")
    public CommonResult<MuseummodelRespVO> getMuseumModel(@RequestParam("id") Integer id) {
        MuseummodelDO result = museumModelService.selectMuseumModel(id);
        MuseummodelRespVO result1 = BeanUtils.toBean(result, MuseummodelRespVO.class);
        return CommonResult.success(result1);
    }

//    @GetMapping("/page")
//    @Operation(summary = "获得用户分页列表")
//    @PreAuthorize("@ss.hasPermission('system:user:query')")
//    public CommonResult<PageResult<MuseummodelRespVO>> getUserPage(@Valid MuseummodelPageReqVO pageReqVO) {
//        // 获得用户分页列表
//        PageResult<MuseummodelDO> pageResult = MuseummodelService.getUserPage(pageReqVO);
//        if (CollUtil.isEmpty(pageResult.getList())) {
//            return success(new PageResult<>(pageResult.getTotal()));
//        }
//        return null;
//    }


@GetMapping("/page")
@Operation(summary = "获得模型分页")
@PreAuthorize("@ss.hasPermission('system:tenant:query')")
public CommonResult<PageResult<MuseummodelRespVO>> getPage(@Valid MuseummodelPageReqVO pageVO) {
    PageResult<MuseummodelDO> pageResult = museumModelService.getMuseummodelPage(pageVO);
    return success(BeanUtils.toBean(pageResult,MuseummodelRespVO.class));
}

}


