using Microsoft.AspNetCore.Mvc;
using QYZH.InteractiveMagazine.IService;
using QYZH.InteractiveMagazine.Models.Dto;
using QYZH.InteractiveMagazine.Models.Dto.Bag;

namespace QYZH.InteractiveMagazine.WeChatApi.Controllers;

/// <summary>
/// 小程序背包控制器
/// </summary>
public class BagController(IWxMallService mallService, ILogger<BagController> logger) : WeChatBaseController
{
    /// <summary>
    /// 获取背包物品列表
    /// </summary>
    /// <param name="itemType">物品类型筛选（可选）: MakeUpCard, PetBg</param>
    [HttpGet("items")]
    public async Task<BaseResponse<List<UserBagOutput>>> GetBagItems([FromQuery] string? itemType = null)
    {
        var userId = GetCurrentUserId();
        if (userId == 0) return Fail("未获取到用户信息") as dynamic;

        var items = await mallService.GetBagItemsAsync(userId, itemType);
        return Success(items);
    }

    /// <summary>
    /// 使用背包物品（补签卡等消耗品）
    /// </summary>
    [HttpPost("useItem")]
    public async Task<BaseResponse<UseItemOutput>> UseItem([FromBody] UseItemInput input)
    {
        var userId = GetCurrentUserId();
        if (userId == 0) return Fail("未获取到用户信息") as dynamic;

        var result = await mallService.UseItemAsync(userId, input);
        return Success(result);
    }

    /// <summary>
    /// 宠物换肤
    /// </summary>
    [HttpPost("equipSkin")]
    public async Task<BaseResponse<object>> EquipSkin([FromBody] EquipSkinInput input)
    {
        var userId = GetCurrentUserId();
        if (userId == 0) return Fail("未获取到用户信息") as dynamic;

        await mallService.EquipSkinAsync(userId, input);
        return Success<object>(null!, input.SkinId == 0 ? "已恢复默认皮肤" : "换肤成功");
    }
}
