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.BrowsingHistoryPageReq;
import com.seer.teach.mall.request.BrowsingSaveReq;
import com.seer.teach.mall.response.BrowsingHistoryPageResp;
import com.seer.teach.mall.service.BrowsingHistoryService;
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-18 11:09
 */
@RestController
@RequestMapping("/app/user/browsing")
@Tag(name = "APP - 我的足迹管理")
@Validated
@RequiredArgsConstructor
@EncryptionAnnotation
@DecryptionAnnotation
@SaCheckLogin(type = StpUtil.TYPE)
public class AppBrowsingHistoryController {

    private final BrowsingHistoryService browsingHistoryService;


    @PostMapping
    @SaCheckPermission("app:browsing-history:create")
    @LogPrint
    @Operation(summary = "新增浏览足迹")
    public ResultBean addBrowsingHistory(@RequestBody @Validated BrowsingSaveReq params){
        browsingHistoryService.addBrowsingHistory(params);
        return ResultBean.success();
    }

    @PostMapping("/delete")
    @SaCheckPermission("app:browsing-history:delete")
    @LogPrint
    @Operation(summary = "删除浏览足迹")
    public ResultBean deleteBrowsingHistory(@RequestBody List<Integer> ids){
        browsingHistoryService.deleteBrowsingHistory(ids);
        return ResultBean.success();
    }

    @DeleteMapping("/history")
    @SaCheckPermission("app:browsing-history:clear")
    @LogPrint
    @Operation(summary = "清空浏览足迹")
    public ResultBean clearBrowsingHistory(){
        browsingHistoryService.clearBrowsingHistory();
        return ResultBean.success();
    }

    @PostMapping("/list")
    @SaCheckPermission("app:browsing-history:list")
    @LogPrint
    @Operation(summary = "分页查询浏览足迹")
    public ResultBean<PageListBean<BrowsingHistoryPageResp>> getBrowsingHistoryPage(@RequestBody @Validated BrowsingHistoryPageReq params) {
        return ResultBean.success(browsingHistoryService.getBrowsingHistoryPage(params));
    }
}
