using HoneyBox.Admin.Business.Attributes;
using HoneyBox.Admin.Business.Models;
using HoneyBox.Admin.Business.Models.Goods;
using HoneyBox.Admin.Business.Services.Interfaces;
using Microsoft.AspNetCore.Mvc;

namespace HoneyBox.Admin.Business.Controllers;

/// <summary>
/// 奖品管理控制器
/// </summary>
[Route("api/admin/business/[controller]")]
public class PrizesController : BusinessControllerBase
{
    private readonly IGoodsService _goodsService;

    public PrizesController(IGoodsService goodsService)
    {
        _goodsService = goodsService;
    }

    /// <summary>
    /// 更新奖品
    /// </summary>
    /// <param name="id">奖品ID</param>
    /// <param name="request">更新请求</param>
    /// <returns>操作结果</returns>
    [HttpPut("{id}")]
    [BusinessPermission("goods:edit")]
    public async Task<IActionResult> UpdatePrize(int id, [FromBody] PrizeUpdateRequest request)
    {
        try
        {
            var result = await _goodsService.UpdatePrizeAsync(id, request);
            return result ? Ok("更新成功") : Error(BusinessErrorCodes.InternalError, "更新失败");
        }
        catch (BusinessException ex)
        {
            return Error(ex.Code, ex.Message);
        }
    }

    /// <summary>
    /// 删除奖品
    /// </summary>
    /// <param name="id">奖品ID</param>
    /// <returns>操作结果</returns>
    [HttpDelete("{id}")]
    [BusinessPermission("goods:edit")]
    public async Task<IActionResult> DeletePrize(int id)
    {
        try
        {
            var result = await _goodsService.DeletePrizeAsync(id);
            return result ? Ok("删除成功") : Error(BusinessErrorCodes.InternalError, "删除失败");
        }
        catch (BusinessException ex)
        {
            return Error(ex.Code, ex.Message);
        }
    }
}
