using MBN_STOCK_WEBVIEW.Core.Playout;
using MBN_STOCK_WEBVIEW.Core.Playout.Scenes;

namespace MBN_STOCK_WEBVIEW.Playout.Configuration;

public sealed class PlayoutOptions
{
    /// <summary>
    /// Process-local provenance set only by the exact Debug Development Live
    /// bootstrap loader. It is not a JSON or environment configuration surface.
    /// </summary>
    internal bool DevelopmentLiveBootstrapApplied { get; set; }

    /// <summary>
    /// Canonical executable-relative Cuts root captured by the Development Live
    /// loader. Final validation uses it to prevent later replacement of the
    /// verified build payload.
    /// </summary>
    internal string? DevelopmentLiveExecutableSceneDirectory { get; set; }

    public PlayoutMode Mode { get; set; } = PlayoutMode.DryRun;

    public string Host { get; set; } = "127.0.0.1";

    public int Port { get; set; } = 30001;

    /// <summary>KTAPConnect bTCP argument. The legacy application uses 1.</summary>
    public int TcpMode { get; set; } = 1;

    /// <summary>KTAPConnect nClientPort argument. Zero lets the SDK choose.</summary>
    public int ClientPort { get; set; }

    public int? OutputChannel { get; set; }

    public int LayoutIndex { get; set; } = 10;

    /// <summary>MainForm ComboDi.SelectedIndex (0..19) passed to SetSceneEffectType.</summary>
    public int LegacySceneFadeDuration { get; set; } = 6;

    /// <summary>
    /// Trusted MainForm-level background selection. The asset is always a path relative
    /// to LegacyBackgroundDirectory and is never accepted from Web content.
    /// </summary>
    public LegacySceneBackgroundKind LegacySceneBackgroundKind { get; set; } =
        LegacySceneBackgroundKind.None;

    public string? LegacySceneBackgroundAssetPath { get; set; }

    public int LegacySceneBackgroundVideoLoopCount { get; set; } = 2004;

    public bool LegacySceneBackgroundVideoLoopInfinite { get; set; } = true;

    /// <summary>
    /// External absolute root containing operator-selectable MainForm backgrounds.
    /// When omitted, the original layout is retained by deriving a sibling "배경"
    /// directory from SceneDirectory (Cuts\..\배경). This root is never merged with
    /// the trusted scene/Cuts root.
    /// </summary>
    public string? LegacyBackgroundDirectory { get; set; }

    /// <summary>
    /// External absolute root containing vendor .t2s scenes. Required in Test and Live modes.
    /// </summary>
    public string? SceneDirectory { get; set; }

    public string? TestProcessWindowTitlePattern { get; set; }

    /// <summary>
    /// Closed scene-name allowlist for every real Test or Live output command.
    /// The property name is retained for existing local configuration files.
    /// </summary>
    public List<string> TestSceneAllowlist { get; set; } = [];

    public bool TrustedLiveOutputEnabled { get; set; }

    public int QueueCapacity { get; set; } = 64;

    public int ConnectTimeoutMilliseconds { get; set; } = 5_000;

    public int OperationTimeoutMilliseconds { get; set; } = 5_000;

    public int DisconnectTimeoutMilliseconds { get; set; } = 3_000;

    public int ProcessPollIntervalMilliseconds { get; set; } = 1_000;

    public int ReconnectDelayMilliseconds { get; set; } = 1_000;

    public int MaximumReconnectAttempts { get; set; } = 3;

    public bool ReconnectEnabled { get; set; } = true;

    /// <summary>
    /// Optional trusted local safety ceiling for timer-driven same-scene refreshes
    /// started by one TAKE IN. Null preserves the legacy continuous-refresh behavior;
    /// zero disables automatic refresh; a positive value stops after that many
    /// successful refresh dispatches and drains the final play callback before
    /// reporting that the limit was reached. Web content cannot change this value.
    /// </summary>
    public int? MaximumAutomaticRefreshesPerTakeIn { get; set; }
}
