using RolemasterDb.App.Features;

namespace RolemasterDb.App.Components.Shared;

public sealed class CriticalEffectEditorModel
{
    public string EffectCode { get; set; } = string.Empty;
    public string? Target { get; set; }
    public int? ValueInteger { get; set; }
    public decimal? ValueDecimal { get; set; }
    public string? ValueExpression { get; set; }
    public int? DurationRounds { get; set; }
    public int? PerRound { get; set; }
    public int? Modifier { get; set; }
    public string? BodyPart { get; set; }
    public bool IsPermanent { get; set; }
    public string SourceType { get; set; } = "symbol";
    public string? SourceText { get; set; }
    public string? OriginKey { get; set; }
    public bool IsOverridden { get; set; }

    public static CriticalEffectEditorModel FromItem(CriticalEffectEditorItem item) =>
        new()
        {
            EffectCode = item.EffectCode,
            Target = item.Target,
            ValueInteger = item.ValueInteger,
            ValueDecimal = item.ValueDecimal,
            ValueExpression = item.ValueExpression,
            DurationRounds = item.DurationRounds,
            PerRound = item.PerRound,
            Modifier = item.Modifier,
            BodyPart = item.BodyPart,
            IsPermanent = item.IsPermanent,
            SourceType = item.SourceType,
            SourceText = item.SourceText,
            OriginKey = item.OriginKey,
            IsOverridden = item.IsOverridden
        };

    public CriticalEffectEditorItem ToItem() =>
        new(
            EffectCode,
            Target,
            ValueInteger,
            ValueDecimal,
            ValueExpression,
            DurationRounds,
            PerRound,
            Modifier,
            BodyPart,
            IsPermanent,
            SourceType,
            SourceText,
            OriginKey,
            IsOverridden);

    public CriticalEffectEditorModel Clone() =>
        new()
        {
            EffectCode = EffectCode,
            Target = Target,
            ValueInteger = ValueInteger,
            ValueDecimal = ValueDecimal,
            ValueExpression = ValueExpression,
            DurationRounds = DurationRounds,
            PerRound = PerRound,
            Modifier = Modifier,
            BodyPart = BodyPart,
            IsPermanent = IsPermanent,
            SourceType = SourceType,
            SourceText = SourceText,
            OriginKey = OriginKey,
            IsOverridden = IsOverridden
        };
}
