package com.czg.controller.admin;

import com.czg.account.dto.PictureGalleryDTO;
import com.czg.account.param.PictureGalleryParam;
import com.czg.account.service.PictureGalleryService;
import com.czg.log.annotation.OperationLog;
import com.czg.resp.CzgResult;
import com.czg.utils.AssertUtil;
import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.InsertGroup;
import com.mybatisflex.core.paginate.Page;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 图库
 *
 * @author Tankaikai tankaikai@aliyun.com
 * @since 1.0 2025-02-26
 */
@AllArgsConstructor
@RestController
@RequestMapping("/admin/picture/gallery")
public class PictureGalleryController {
    private final PictureGalleryService pictureGalleryService;

    /**
     * 分页
     */
    @GetMapping("page")
    @OperationLog("图库-分页")
    //@SaAdminCheckPermission("pictureGallery:page")
    public CzgResult<Page<PictureGalleryDTO>> getPictureGalleryPage(PictureGalleryDTO param) {
        Page<PictureGalleryDTO> data = pictureGalleryService.getPictureGalleryPage(param);
        return CzgResult.success(data);
    }

    /**
     * 添加图片
     */
    @PostMapping
    @OperationLog("图库-添加图片")
    //@SaAdminCheckPermission("pictureGallery:add")
    public CzgResult<Void> addPictureGallery(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) PictureGalleryParam param) {
        pictureGalleryService.addPictureGallery(param);
        return CzgResult.success();
    }

    /**
     * 删除
     *
     * @param id 图库id
     */
    @DeleteMapping("{id}")
    @OperationLog("图库-删除图片")
    //@SaAdminCheckPermission("pictureGallery:delete")
    public CzgResult<Void> deletePictureGallery(@PathVariable("id") Long id) {
        //效验数据
        AssertUtil.isNull(id, "{}不能为空", "id");
        pictureGalleryService.deletePictureGallery(id);
        return CzgResult.success();
    }

}