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.MuseumPictureRespVO;
import cn.iocoder.yudao.module.museum.controller.admin.museumpicture.vo.MuseumPictureSaveVO;
import cn.iocoder.yudao.module.museum.controller.admin.museumpicture.vo.PicturePageReqVO;
import cn.iocoder.yudao.module.museum.dal.database.museumpicture.MuseumPictureDO;
import cn.iocoder.yudao.module.museum.service.museumpicture.MuseumPictureService;
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.beans.factory.annotation.Autowired;
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/picture")
@Validated

public class MuseumPictureController {

    @Resource
    private MuseumPictureService museumPictureService;
    @Autowired
    private PictureGroupService pictureGroupService;
    private PicturePageReqVO pageVO;

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

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

    @DeleteMapping("/delete")
    @Operation(summary = "删除图片")
    public CommonResult<Boolean> deleteMuseumPicture(@RequestParam("pictureId") Integer pictureId) {
        museumPictureService.deleteMuseumPicture(pictureId);
        return CommonResult.success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "查找图片")
    public CommonResult<MuseumPictureRespVO> getMuseumPicture(@RequestParam("pictureId") Integer pictureId) {

//        if (pictureId==null) {
//            return CommonResult.error(1,"照片id不存在");
//        }else {
        MuseumPictureDO result = museumPictureService.selectMuseumPicture(pictureId);
        MuseumPictureRespVO result1 = BeanUtils.toBean(result, MuseumPictureRespVO.class);
        return CommonResult.success(result1);
//        }
    }

    @GetMapping("/get")
    @Operation(summary = "查找图片")
    public CommonResult<MuseumPictureRespVO> getMuseumPictureGroup(@RequestParam("groupId") Integer groupId) {

//        if (pictureId==null) {
//            return CommonResult.error(1,"没有符合的照片组图片");
//        }else {
        MuseumPictureDO result = museumPictureService.selectMuseumPicture(groupId);
        MuseumPictureRespVO list1 = BeanUtils.toBean(result, MuseumPictureRespVO.class);
        return CommonResult.success(list1);
//        }
    }


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

}