using System.Text.Json;

namespace Sonex.Client.Controls;

public sealed class AnimatedBackgroundAnimationSettings
{
    public AnimatedBackgroundBlendMode BlendMode { get; set; } = AnimatedBackgroundBlendMode.SourceOver;

    public string BackgroundColor { get; set; } = "transparent";
    public string? BackgroundImageUrl { get; set; }
    public string BackgroundSize { get; set; } = "cover";
    public string BackgroundPosition { get; set; } = "center center";
    public string BackgroundRepeat { get; set; } = "no-repeat";

    public double BoundsTop { get; set; } = 80;
    public double BoundsRight { get; set; } = -100;
    public double BoundsBottom { get; set; } = -100;
    public double BoundsLeft { get; set; } = -100;

    public AnimatedBackgroundDirection Direction { get; set; } = AnimatedBackgroundDirection.Left;

    public double ScrollSpeed { get; set; } = 21;
    public double NodeSpawnRate { get; set; } = 10;
    public int MaxNodes { get; set; } = 20;
    public double MinNodeRadius { get; set; } = 12;
    public double MaxNodeRadius { get; set; } = 32;
    public double MaxNodeSpeed { get; set; } = 40;

    public double CollisionPadding { get; set; } = 48;
    public int CollisionIterations { get; set; } = 5;

    public double FadeIn { get; set; } = 110;
    public double FadeOut { get; set; } = 110;

    public string[] NodeColors { get; set; } =
    [
        "#C5CFD4",
        "#C5CFD4",
        "#C5CFD4",
        "#C5CFD4",
        "#C5CFD4",
        "#C5CFD4",
        "#C5CFD4",
        "#F6D988",
        "#F6D988",
        "#F6D988"
    ];

    public string[] IconUris { get; set; } = [];

    public bool DrawIcons { get; set; } = true;
    public double IconMinDiameter { get; set; } = 1;
    public double IconScale { get; set; } = 1;

    public bool DrawEdges { get; set; } = false;
    public bool FillNodes { get; set; } = false;
    public double NodesOpacity { get; set; } = 1.0;

    public bool PulseIconWidth { get; set; } = false;
    public double PulseIconWidthAmplitude { get; set; } = 0.22;
    public double PulseIconWidthFrequency { get; set; } = 6.0;

    public double InvisibleBouncePad { get; set; } = 20;
    public double BounceDamping { get; set; } = 0.97;

    public double CollisionPositionCorrection { get; set; } = 1.0;
    public double CollisionSlopPx { get; set; } = 0.40;
    public double CollisionMaxCorrectionPx { get; set; } = 10.0;
    public double CollisionSeparationSpring { get; set; } = 6.0;
    public double CollisionImpulseDamping { get; set; } = 0.03;
    public double CollisionTangentFriction { get; set; } = 0.01;

    public int MinLinksPerNode { get; set; } = 1;
    public int MaxLinksPerNode { get; set; } = 3;
    public bool EnableExtraLink { get; set; } = true;
    public double ExtraLinkChance { get; set; } = 0.25;

    public bool FireworksEnabled { get; set; } = false;
    public double FireworksOpacity { get; set; } = 0.8;
    public double FireworksFadeFillAlpha { get; set; } = 0.05;
    public int FireworksMaxParticles { get; set; } = 400;
    public int FireworksMaxRockets { get; set; } = 5;
    public int FireworksLaunchIntervalMs { get; set; } = 800;
    public double FireworksLaunchBottomOffset { get; set; } = 100;
    public double FireworksRocketVelocityMin { get; set; } = 4;
    public double FireworksRocketVelocityRange { get; set; } = 4;
    public double FireworksRocketHorizontalVelocity { get; set; } = 4;
    public double FireworksRocketSize { get; set; } = 2;
    public double FireworksRocketGravity { get; set; } = 0.05;
    public double FireworksParticleSize { get; set; } = 2;
    public int FireworksExplosionMinParticles { get; set; } = 50;
    public int FireworksExplosionExtraParticles { get; set; } = 80;
    public double FireworksParticleGravity { get; set; } = 0.25;
    public double FireworksParticleResistance { get; set; } = 0.92;
    public double FireworksParticleShrinkMin { get; set; } = 0.96;
    public double FireworksParticleShrinkRange { get; set; } = 0.03;
    public bool FireworksParticleFlicker { get; set; } = true;
    public string[] FireworksColors { get; set; } = [];
}

public enum AnimatedBackgroundBlendMode
{
    SourceOver = 0,
    Lighter = 1,
    Multiply = 2,
    Screen = 3,
    Overlay = 4
}

public enum AnimatedBackgroundDirection
{
    Up = 0,
    Right = 1,
    Down = 2,
    Left = 3
}
