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.core.page.PageRequest;
import org.xyzh.common.dto.resource.TbBanner;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * @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(TbBanner filter) {
        return bannerService.getBannerList(filter);
    }

    /**
     * 根据ID获取横幅详情
     */
    @PostMapping("/banner/page")
    public ResultDomain<TbBanner> getBannerPage(@RequestBody PageRequest<TbBanner> pageRequest) {
        return bannerService.getBannerPage(pageRequest.getPageParam(), pageRequest.getFilter());
    }

    /**
     * 创建横幅
     */
    @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")
    public ResultDomain<Boolean> deleteBanner(@RequestBody TbBanner banner) {
        return bannerService.deleteBanner(banner.getBannerID());
    }

    /**
     * 更新横幅状态
     */
    @PutMapping("/banner/status")
    public ResultDomain<TbBanner> updateBannerStatus(@RequestBody TbBanner banner) {
        return bannerService.updateBannerStatus(banner.getBannerID(), banner.getStatus());
    }

    /**
     * 获取首页横幅列表
     */
    @GetMapping("/home")
    public ResultDomain<TbBanner> getHomeBannerList() {
        return bannerService.selectHomeBanners();
    }
    


}
