using UnityEngine;

namespace CoolGameX
{
    /// <summary>
    /// Project settings for the SDK. Lives at <c>Assets/Resources/CoolGameXSettings.asset</c>
    /// and is edited from <b>Tools › Cool GameX › Setup</b>. Contains no secrets —
    /// your Editor sign-in is stored per machine, never in the project.
    /// </summary>
    [CreateAssetMenu(menuName = "Cool GameX/Settings", fileName = "CoolGameXSettings")]
    public class CoolGameXSettings : ScriptableObject
    {
        public const string ResourceName = "CoolGameXSettings";
        public const string DefaultServerUrl = "https://coolgamex-davi.fly.dev";

        [Header("Game")]
        [Tooltip("Your game's slug, exactly as in the Creator dashboard.")]
        public string gameSlug = "";

        [Tooltip("Cool GameX backend. When the game is started from the launcher the launcher's backend is used automatically.")]
        public string serverUrl = DefaultServerUrl;

        [Header("Startup")]
        [Tooltip("Start the SDK automatically when the game launches — no code or scene object needed.")]
        public bool autoInitialize = true;

        [Header("Playtime")]
        [Tooltip("Auto: the launcher times games it starts; the SDK tracks only standalone runs, so minutes are never counted twice.")]
        public PlaytimeTracking playtime = PlaytimeTracking.Auto;

        [Tooltip("While tracking, report playtime every N minutes so a crash loses at most N minutes.")]
        [Min(1)] public int heartbeatMinutes = 5;

        [Header("Reliability")]
        [Tooltip("Save unlocks, stats and playtime while offline and sync them automatically later.")]
        public bool offlineQueue = true;

        [Header("Developer tools")]
        public CGXLogLevel logLevel = CGXLogLevel.Warnings;

        [Tooltip("An on-screen panel with SDK status, test unlocks and recent requests.")]
        public DebugOverlayMode debugOverlay = DebugOverlayMode.EditorAndDevelopmentBuilds;

        [Tooltip("Key that opens the debug overlay.")]
        public KeyCode debugOverlayKey = KeyCode.F8;

        [Tooltip("Draw the SDK's own 'Achievement unlocked' toasts. The launcher already shows popups for games it starts.")]
        public ToastMode inGameToasts = ToastMode.WhenNotLaunchedFromLauncher;

        /// <summary>The project's settings asset, or null if it hasn't been created yet.</summary>
        public static CoolGameXSettings Load() => Resources.Load<CoolGameXSettings>(ResourceName);
    }
}
