using AssetManager.API.DTOs;
using AssetManager.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace AssetManager.API.Controllers;

[ApiController]
[Route("api/[controller]")]
[Authorize]
public class AssetController : ControllerBase
{
    private readonly ILogger<AssetController> _logger;

    public AssetController(ILogger<AssetController> logger)
    {
        _logger = logger;
    }

    [HttpGet]
    public ActionResult<ApiResponse<TotalAssetResponse>> GetTotalAssets()
    {
        try
        {
            _logger.LogInformation("Request to get total assets");
            
            // 模拟返回总资产数据
            var response = new TotalAssetResponse
            {
                TotalValue = 125000.50,
                TodayProfit = 250.75,
                TotalReturnRate = 12.5
            };

            _logger.LogInformation("Total assets retrieved successfully");
            
            return Ok(new ApiResponse<TotalAssetResponse>
            {
                Code = AssetManager.Models.StatusCodes.Success,
                Data = response,
                Message = "Success"
            });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error retrieving total assets");
            
            return StatusCode(AssetManager.Models.StatusCodes.InternalServerError, new ApiResponse<TotalAssetResponse>
            {
                Code = AssetManager.Models.StatusCodes.InternalServerError,
                Data = null,
                Message = ex.Message
            });
        }
    }

    [HttpGet("holdings")]
    public ActionResult<ApiResponse<List<HoldingItem>>> GetHoldings()
    {
        try
        {
            _logger.LogInformation("Request to get holdings");
            
            // 模拟返回持仓组合数据
            var holdings = new List<HoldingItem>
            {
                new HoldingItem
                {
                    Id = "1",
                    Name = "沪深300指数增强",
                    Tags = "指数增强",
                    Status = "监控中",
                    StatusType = "green",
                    IconChar = "沪",
                    IconBgClass = "bg-blue-500",
                    IconTextClass = "text-white",
                    Value = 50000.00,
                    ReturnRate = 8.5,
                    ReturnType = "positive"
                },
                new HoldingItem
                {
                    Id = "2",
                    Name = "中证500量化",
                    Tags = "量化策略",
                    Status = "等待信号",
                    StatusType = "gray",
                    IconChar = "中",
                    IconBgClass = "bg-green-500",
                    IconTextClass = "text-white",
                    Value = 35000.00,
                    ReturnRate = -2.1,
                    ReturnType = "negative"
                },
                new HoldingItem
                {
                    Id = "3",
                    Name = "债券型基金",
                    Tags = "固定收益",
                    Status = "监控中",
                    StatusType = "green",
                    IconChar = "债",
                    IconBgClass = "bg-yellow-500",
                    IconTextClass = "text-white",
                    Value = 40000.00,
                    ReturnRate = 3.2,
                    ReturnType = "positive"
                }
            };

            _logger.LogInformation("Holdings retrieved successfully");
            
            return Ok(new ApiResponse<List<HoldingItem>>
            {
                Code = AssetManager.Models.StatusCodes.Success,
                Data = holdings,
                Message = "Success"
            });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error retrieving holdings");
            
            return StatusCode(AssetManager.Models.StatusCodes.InternalServerError, new ApiResponse<List<HoldingItem>>
            {
                Code = AssetManager.Models.StatusCodes.InternalServerError,
                Data = null,
                Message = ex.Message
            });
        }
    }
}