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.banner.BannerService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.dto.resource.TbBanner;

/**
 * @description 横幅控制器
 * @filename BannerController.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-10-15
 */
@RestController
@RequestMapping("/news/banners")
public class BannerController {
    private static final Logger logger = LoggerFactory.getLogger(BannerController.class);

    @Autowired
    private BannerService bannerService;

    /**
     * 获取横幅列表
     */
    @GetMapping("/list")
    public ResultDomain<TbBanner> getBannerList() {
        return bannerService.getBannerList(null);
    }

    /**
     * 根据ID获取横幅详情
     */
    @GetMapping("/banner/{bannerID}")
    public ResultDomain<TbBanner> getBannerById(@PathVariable String bannerID) {
        return bannerService.getBannerById(bannerID);
    }

    /**
     * 创建横幅
     */
    @PostMapping("/banner")
    public ResultDomain<TbBanner> createBanner(@RequestBody TbBanner banner) {
        return bannerService.createBanner(banner);
    }

    /**
     * 更新横幅
     */
    @PutMapping("/banner")
    public ResultDomain<TbBanner> updateBanner(@RequestBody TbBanner banner) {
        return bannerService.updateBanner(banner);
    }

    /**
     * 删除横幅
     */
    @DeleteMapping("/banner/{bannerID}")
    public ResultDomain<Boolean> deleteBanner(@PathVariable String bannerID) {
        return bannerService.deleteBanner(bannerID);
    }

    /**
     * 更新横幅状态
     */
    @PutMapping("/banner/{bannerID}/status")
    public ResultDomain<TbBanner> updateBannerStatus(
            @PathVariable String bannerID,
            @RequestParam Integer status) {
        return bannerService.updateBannerStatus(bannerID, status);
    }

    /**
     * 更新横幅排序
     */
    @PutMapping("/banner/{bannerID}/order")
    public ResultDomain<TbBanner> updateBannerOrder(
            @PathVariable String bannerID,
            @RequestParam Integer orderNum) {
        return bannerService.updateBannerOrder(bannerID, orderNum);
    }

    /**
     * 获取活跃横幅
     */
    @GetMapping("/active")
    public ResultDomain<TbBanner> getActiveBanners(@RequestParam(required = false) Integer limit) {
        return bannerService.getActiveBanners(limit);
    }
}
