using Microsoft.AspNetCore.Mvc;
using QYZH.InteractiveMagazine.IService;
using QYZH.InteractiveMagazine.Models.Dto;
using QYZH.InteractiveMagazine.Models.Dto.Banner;
using QYZH.InteractiveMagazine.Models.Enum;

namespace QYZH.InteractiveMagazine.WebApi.Controllers;

/// <summary>
/// 轮播图管理控制器
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
public class BannerController(IBannerService bannerService) : BaseController
{
    /// <summary>
    /// 创建轮播图
    /// </summary>
    /// <param name="input">轮播图信息</param>
    /// <returns>创建后的轮播图信息</returns>
    [HttpPost]
    public async Task<BaseResponse<BannerOutput>> CreateAsync([FromBody] BannerInput input)
    {
        var result = await bannerService.CreateAsync(input);
        return Success(result, "创建轮播图成功");
    }

    /// <summary>
    /// 更新轮播图
    /// </summary>
    /// <param name="id">轮播图ID</param>
    /// <param name="input">轮播图信息</param>
    /// <returns>更新后的轮播图信息</returns>
    [HttpPut("{id}")]
    public async Task<BaseResponse<BannerOutput>> UpdateAsync(long id, [FromBody] BannerInput input)
    {
        var result = await bannerService.UpdateAsync(id, input);
        return Success(result, "更新轮播图成功");
    }

    /// <summary>
    /// 删除轮播图
    /// </summary>
    /// <param name="id">轮播图ID</param>
    /// <returns>操作结果</returns>
    [HttpDelete("{id}")]
    public async Task<BaseResponse<object>> DeleteAsync(long id)
    {
        await bannerService.DeleteAsync(id);
        return Success(new object(), "删除轮播图成功");
    }

    /// <summary>
    /// 根据ID获取轮播图
    /// </summary>
    /// <param name="id">轮播图ID</param>
    /// <returns>轮播图信息</returns>
    [HttpGet("{id}")]
    public async Task<BaseResponse<BannerOutput>> GetByIdAsync(long id)
    {
        var result = await bannerService.GetByIdAsync(id);
        return Success(result);
    }

    /// <summary>
    /// 分页查询轮播图列表
    /// </summary>
    /// <param name="input">查询条件</param>
    /// <returns>分页结果</returns>
    [HttpPost("list")]
    public async Task<BaseResponse<PageListModel<BannerOutput>>> GetListAsync([FromBody] BannerQueryInput input)
    {
        var result = await bannerService.GetListAsync(input);
        return Success(result);
    }

    /// <summary>
    /// 更新轮播图启用/禁用状态
    /// </summary>
    /// <param name="id">轮播图ID</param>
    /// <returns>操作结果</returns>
    [HttpPut("{id}/status")]
    public async Task<BaseResponse<bool>> UpdateStatusAsync(long id)
    {
        var result = await bannerService.UpdateStatusAsync(id);
        return Success(result, "更新轮播图状态成功");
    }
}
