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

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.museumpicture.vo.PictureGroupRespVO;
import cn.iocoder.yudao.module.museum.controller.admin.museumpicture.vo.PictureGroupSaveVO;
import cn.iocoder.yudao.module.museum.controller.admin.museumpicture.vo.PicturePageReqVO;
import cn.iocoder.yudao.module.museum.dal.database.museumpicture.PictureGroupDO;
import cn.iocoder.yudao.module.museum.service.museumpicture.PictureGroupService;
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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "博物馆-图片组")
@RestController
@RequestMapping("/museum/pictureGroup")
@Validated

public class PictureGroupController {

    @Resource
    private PictureGroupService PictureGroupService;

    @PostMapping("/create")
    @Operation(summary = "新增图片组")
    public Integer createPictureGroup(@RequestBody PictureGroupSaveVO saveVO){
        return PictureGroupService.createPictureGroup(saveVO);
    }

    @PutMapping("/update")
    @Operation(summary = "更新图片组")
    public CommonResult<Boolean> updatePictureGroup(@RequestBody PictureGroupSaveVO saveVO) {
        PictureGroupService.updatePictureGroup(saveVO);
        return CommonResult.success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除标本")
    public CommonResult<Boolean> deletePictureGroup(@RequestParam("id") Integer id){
        PictureGroupService.deletePictureGroup(id);
        return CommonResult.success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "查找图片组")
    public CommonResult<PictureGroupRespVO> getPictureGroup(@RequestParam("id") Integer id) {
        PictureGroupDO result = PictureGroupService.selectPictureGroup(id);
        PictureGroupRespVO result1 = BeanUtils.toBean(result, PictureGroupRespVO.class);
        return CommonResult.success(result1);
    }

    @GetMapping("/page")
    @Operation(summary = "获得照片组分页")
    @PreAuthorize("@ss.hasPermission('system:tenant:query')")
    public CommonResult<PageResult<PictureGroupRespVO>> getPictureGroupPage(@Validated PicturePageReqVO pageVO) {
        PageResult<PictureGroupDO> pageResult = PictureGroupService.getPictureGroupPage(pageVO);
        return success(BeanUtils.toBean(pageResult, PictureGroupRespVO.class));
    }
}
