package com.czg.controller.admin;

import com.czg.account.dto.PictureClassifyDTO;
import com.czg.account.service.PictureClassifyService;
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.czg.validator.group.UpdateGroup;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 图片分类
 *
 * @author Tankaikai tankaikai@aliyun.com
 * @since 1.0 2025-02-26
 */
@AllArgsConstructor
@RestController
@RequestMapping("/admin/picture/classify")
public class PictureClassifyController {
    private final PictureClassifyService pictureClassifyService;

    /**
     * 列表
     */
    @GetMapping("list")
    @OperationLog("图片分类-列表")
    //@SaAdminCheckPermission("pictureClassify:list")
    public CzgResult<List<PictureClassifyDTO>> getPictureClassifyList(PictureClassifyDTO param) {
        List<PictureClassifyDTO> data = pictureClassifyService.getPictureClassifyList(param);
        return CzgResult.success(data);
    }

    /**
     * 新增
     */
    @PostMapping
    @OperationLog("图片分类-新增")
    //@SaAdminCheckPermission("pictureClassify:add")
    public CzgResult<Void> addPictureClassify(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) PictureClassifyDTO dto) {
        pictureClassifyService.addPictureClassify(dto);
        return CzgResult.success();
    }

    /**
     * 修改
     */
    @PutMapping
    @OperationLog("图片分类-修改")
    //@SaAdminCheckPermission("pictureClassify:update")
    public CzgResult<Void> updatePictureClassify(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) PictureClassifyDTO dto) {
        pictureClassifyService.updatePictureClassify(dto);
        return CzgResult.success();
    }

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