using Application.Services.Database;

namespace Application.Endpoints.Pacients.Login;

public class PacientLoginHandler
{
    private readonly IPacientRepository _database;

    public PacientLoginHandler(IPacientRepository database)
    {
        _database = database;
    }

    public async Task<BaseResponse> Handle(PacientLoginDTO loginDTO)
    {
        var validation = new PacientLoginValidation(_database);
        var validationResult = await validation.ValidateAsync(loginDTO);

        if (!validationResult.IsValid)
        {
            var errorMessage = validationResult.Errors.FirstOrDefault()?.ErrorMessage;
            return new BaseResponse
            {
                Success = false,
                Message = errorMessage,
                Data = null
            };
        }

        return new BaseResponse
        {
            Success = true,
            Message = "Authentication successful",
            Data = null
        };
    }
}
