using System.Text.Json;
using ClaudeDo.Data;

namespace ClaudeDo.Ui;

public sealed class AppSettings
{
    public string DbPath { get; set; } = "~/.todo-app/todo.db";
    public string SignalRUrl { get; set; } = "http://127.0.0.1:47821/hub";

    private static readonly string ConfigPath = Paths.Expand("~/.todo-app/ui.config.json");

    public static AppSettings Load()
    {
        try
        {
            if (File.Exists(ConfigPath))
            {
                var json = File.ReadAllText(ConfigPath);
                return JsonSerializer.Deserialize<AppSettings>(json,
                    new JsonSerializerOptions { PropertyNameCaseInsensitive = true }) ?? new();
            }
        }
        catch
        {
            // Fall through to defaults
        }
        return new();
    }
}
