namespace RelayClient;

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        var username = Environment.GetCommandLineArgs()
            .Skip(1)
            .Chunk(2)
            .Where(x => x.Length == 2 && x[0] == "--user")
            .Select(x => x[1])
            .FirstOrDefault();

        if (string.IsNullOrWhiteSpace(username))
        {
            throw new Exception("Missing required --user argument. Example: --user Keeper317");
        }

        ClientSession.Username = username;
    }

    protected override Window CreateWindow(IActivationState? activationState)
    {
        return new Window(new MainPage(ClientSession.Username))
        {
            Title = $"Relay Client - {ClientSession.Username}"
        };
    }
}