package com.seer.teach.mall.app.good.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.mall.request.GoodsCollectPageReq;
import com.seer.teach.mall.request.GoodsCollectReq;
import com.seer.teach.mall.response.GoodsCollectResp;
import com.seer.teach.mall.app.good.service.IAppCollectService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 嘉多宝宝
 * @Data: 2025-06-16 20:50
 */
@RestController
@RequestMapping("/app/user/collect")
@Tag(name = "APP - 商品收藏管理")
@Validated
@SaCheckLogin(type = StpUtil.TYPE)
@RequiredArgsConstructor
@EncryptionAnnotation
@DecryptionAnnotation
public class AppCollectController {

    private final IAppCollectService collectService;

    @PostMapping
    @SaCheckPermission("app:collect:create")
    @LogPrint
    @Operation(summary = "添加商品收藏")
    public ResultBean addCollect(@RequestBody @Validated GoodsCollectReq params){
        collectService.collectGoods(params);
        return ResultBean.success();
    }

    @PostMapping("/list")
    @SaCheckPermission("app:collect:list")
    @LogPrint
    @Operation(summary = "商品收藏分页查询")
    public ResultBean<PageListBean<GoodsCollectResp>> getGoodsCollectPage(@RequestBody @Validated GoodsCollectPageReq params){
        return ResultBean.success(collectService.getGoodsCollectPage(params));
    }

    @PostMapping("/cancel")
    @SaCheckPermission("app:collect:cancel")
    @LogPrint
    @Operation(summary = "根据商品Id取消收藏商品")
    public ResultBean cancel(@RequestBody List<Integer> goodIds){
        return ResultBean.success(collectService.cancelCollect(goodIds));
    }

    @PostMapping(value = "/detail")
    @SaCheckPermission("app:collect:detail")
    @Operation(summary = "获取用户的商品收藏信息")
    public ResultBean<GoodsCollectResp> detail(@RequestBody GoodsCollectReq params) {
        return ResultBean.success(collectService.getGoodsCollect(StpUtil.getLoginIdAsInt(), params));
    }
}
