using System.ComponentModel.DataAnnotations;
using Managing.Domain.Backtests;
using Managing.Domain.Bots;

namespace Managing.Api.Models.Requests;

public class LightBacktestResponse
{
    [Required] public string Id { get; set; } = string.Empty;
    [Required] public TradingBotConfig Config { get; set; } = new();
    [Required] public decimal FinalPnl { get; set; }
    [Required] public int WinRate { get; set; }
    [Required] public decimal GrowthPercentage { get; set; }
    [Required] public decimal HodlPercentage { get; set; }
    [Required] public DateTime StartDate { get; set; }
    [Required] public DateTime EndDate { get; set; }
    [Required] public decimal? MaxDrawdown { get; set; }
    [Required] public decimal Fees { get; set; }

    [Required] public double? SharpeRatio { get; set; }
    [Required] public double Score { get; set; }
    [Required] public string ScoreMessage { get; set; } = string.Empty;
}

public static class LightBacktestResponseMapper
{
    public static LightBacktestResponse MapFromDomain(Backtest b)
    {
        if (b == null) return null;
        return new LightBacktestResponse
        {
            Id = b.Id,
            Config = b.Config,
            FinalPnl = b.FinalPnl,
            WinRate = b.WinRate,
            GrowthPercentage = b.GrowthPercentage,
            HodlPercentage = b.HodlPercentage,
            StartDate = b.StartDate,
            EndDate = b.EndDate,
            MaxDrawdown = b.Statistics?.MaxDrawdown,
            Fees = b.Fees,
            SharpeRatio = (double?)b.Statistics?.SharpeRatio,
            Score = b.Score,
            ScoreMessage = b.ScoreMessage
        };
    }
}