package org.xyzh.usercenter.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xyzh.api.usercenter.browse.UserBrowseRecordService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.dto.usercenter.TbUserBrowseRecord;

/**
 * @description 用户浏览记录控制器
 * @filename UserBrowseRecordController.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-10-15
 */
@RestController
@RequestMapping("/usercenter/browse")
public class UserBrowseRecordController {
    private static final Logger logger = LoggerFactory.getLogger(UserBrowseRecordController.class);

    @Autowired
    private UserBrowseRecordService userBrowseRecordService;

    /**
     * 获取用户浏览记录
     */
    @GetMapping("/user/{userID}")
    public ResultDomain<TbUserBrowseRecord> getUserBrowseRecords(
            @PathVariable String userID,
            @RequestParam(required = false) Integer resourceType,
            @RequestParam(required = false) Integer limit) {
        return userBrowseRecordService.getUserBrowseRecords(userID, resourceType, limit);
    }

    /**
     * 添加浏览记录
     */
    @PostMapping("/add")
    public ResultDomain<TbUserBrowseRecord> addBrowseRecord(@RequestBody TbUserBrowseRecord browseRecord) {
        return userBrowseRecordService.addBrowseRecord(browseRecord);
    }

    /**
     * 清空浏览记录
     */
    @DeleteMapping("/clear/{userID}")
    public ResultDomain<Boolean> clearBrowseRecords(
            @PathVariable String userID,
            @RequestParam(required = false) Integer resourceType) {
        return userBrowseRecordService.clearUserBrowseRecords(userID, resourceType);
    }

    /**
     * 获取浏览数量
     */
    @GetMapping("/count/{userID}")
    public ResultDomain<Integer> getBrowseCount(
            @PathVariable String userID,
            @RequestParam(required = false) Integer resourceType) {
        return userBrowseRecordService.getBrowseCount(userID, resourceType);
    }
}
