using Managing.Api.Models.Responses;
using Managing.Common;
using AbstractionsPlatformSummaryViewModel = Managing.Application.Abstractions.Models.PlatformSummaryViewModel;

namespace Managing.Api.Extensions;

/// <summary>
/// Extension methods for converting between Platform Summary ViewModels
/// </summary>
public static class PlatformSummaryExtensions
{
    /// <summary>
    /// Converts from the Abstractions PlatformSummaryViewModel to the API PlatformSummaryViewModel
    /// </summary>
    public static PlatformSummaryViewModel ToApiViewModel(this AbstractionsPlatformSummaryViewModel abstractionsModel)
    {
        return new PlatformSummaryViewModel
        {
            TotalAgents = abstractionsModel.TotalAgents,
            TotalActiveStrategies = abstractionsModel.TotalActiveStrategies,
            TotalPlatformPnL = abstractionsModel.TotalPlatformPnL,
            TotalPlatformVolume = abstractionsModel.TotalPlatformVolume,
            TotalPlatformVolumeLast24h = abstractionsModel.TotalPlatformVolumeLast24h,
            TotalOpenInterest = abstractionsModel.TotalOpenInterest,
            TotalPositionCount = abstractionsModel.TotalPositionCount,
            AgentsChange24h = abstractionsModel.AgentsChange24h,
            StrategiesChange24h = abstractionsModel.StrategiesChange24h,
            PnLChange24h = abstractionsModel.PnLChange24h,
            VolumeChange24h = abstractionsModel.VolumeChange24h,
            OpenInterestChange24h = abstractionsModel.OpenInterestChange24h,
            PositionCountChange24h = abstractionsModel.PositionCountChange24h,
            VolumeByAsset = abstractionsModel.VolumeByAsset ?? new Dictionary<Enums.Ticker, decimal>(),
            PositionCountByAsset = abstractionsModel.PositionCountByAsset ?? new Dictionary<Enums.Ticker, int>(),
            PositionCountByDirection = abstractionsModel.PositionCountByDirection?.ToDictionary(
                kvp => kvp.Key,
                kvp => kvp.Value) ?? new Dictionary<Enums.TradeDirection, int>(),
            LastUpdated = abstractionsModel.LastUpdated,
            Last24HourSnapshot = abstractionsModel.Last24HourSnapshot,
            VolumeHistory = abstractionsModel.VolumeHistory,
        };
    }
}