package org.xyzh.news.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.news.recommend.ResourceRecommendService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.dto.resource.TbResourceRecommend;

/**
 * @description 资源推荐控制器
 * @filename ResourceRecommendController.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-10-15
 */
@RestController
@RequestMapping("/news/recommends")
public class ResourceRecommendController {
    private static final Logger logger = LoggerFactory.getLogger(ResourceRecommendController.class);

    @Autowired
    private ResourceRecommendService resourceRecommendService;

    /**
     * 获取推荐列表
     */
    @GetMapping("/list")
    public ResultDomain<TbResourceRecommend> getRecommendList() {
        return resourceRecommendService.getRecommendList();
    }

    /**
     * 根据ID获取推荐详情
     */
    @GetMapping("/recommend/{recommendID}")
    public ResultDomain<TbResourceRecommend> getRecommendById(@PathVariable String recommendID) {
        return resourceRecommendService.getRecommendDetail(recommendID);
    }

    /**
     * 创建推荐
     */
    @PostMapping("/recommend")
    public ResultDomain<TbResourceRecommend> createRecommend(@RequestBody TbResourceRecommend recommend) {
        return resourceRecommendService.addRecommend(recommend);
    }

    /**
     * 更新推荐
     */
    @PutMapping("/recommend")
    public ResultDomain<TbResourceRecommend> updateRecommend(@RequestBody TbResourceRecommend recommend) {
        return resourceRecommendService.updateRecommend(recommend);
    }

    /**
     * 删除推荐
     */
    @DeleteMapping("/recommend/{recommendID}")
    public ResultDomain<Boolean> deleteRecommend(@PathVariable String recommendID) {
        return resourceRecommendService.deleteRecommend(recommendID);
    }

    /**
     * 更新推荐状态
     */
    @PutMapping("/recommend/{recommendID}/status")
    public ResultDomain<TbResourceRecommend> updateRecommendStatus(@PathVariable String recommendID, @RequestParam Integer status) {
        return null;
        // return resourceRecommendService.updateRecommendStatus(recommendID, status);
    }

    /**
     * 更新推荐排序
     */
    @PutMapping("/recommend/{recommendID}/order")
    public ResultDomain<TbResourceRecommend> updateRecommendOrder(@PathVariable String recommendID, @RequestParam Integer orderNum) {
        return resourceRecommendService.updateRecommendOrder(recommendID, orderNum);
    }

    /**
     * 获取活跃推荐
     */
    @GetMapping("/active")
    public ResultDomain<TbResourceRecommend> getActiveRecommends(@RequestParam(required = false) Integer limit) {
        return null;
        // return resourceRecommendService.getActiveRecommends(limit);
    }
}
