using MySqlConnector;
using BCrypt;
using System.ComponentModel.DataAnnotations;

namespace Ticket_System
{
    public class Ticket_System
    {
        Logger logger = new Logger();
        public string userID = "-";

        private string? _token;

        public async Task MainAsync(string[] args)
        {
            if (!await LoginAsync())
                return;

            await LoadTicketsAsync();
        }

        public async Task<bool> LoginAsync()
        {
            var auth = new AuthApiClient("http://localhost:3000");

            string inputuser = "Carl";
            string inputpw = "Deine Fette Mutter";

            var tokenResp = await auth.SignInAsync(inputuser, inputpw);
            if (tokenResp == null || string.IsNullOrWhiteSpace(tokenResp.token))
            {
                logger.Log("Login fehlgeschlagen (API)", userID);
                return false;
            }

            _token = tokenResp.token;

            bool ok = await auth.ValidateTokenAsync(_token);
            logger.Log(ok ? "Token gültig" : "Token ungültig", userID);

            return ok;
        }

        public async Task LoadTicketsAsync()
        {
            // hier würdest du bei weiteren API-Calls einfach den Token mitsenden:
            // Authorization: Bearer <_token>
            await Task.CompletedTask;
        }
    }
}
