package mail

import "testing"

func TestValidateUpdateAccount(t *testing.T) {
	t.Parallel()

	valid := &updateAccountRequest{
		Email:    "user@example.com",
		IMAPHost: "imap.example.com",
		IMAPPort: 993,
		SMTPHost: "smtp.example.com",
		SMTPPort: 587,
	}
	if err := validateUpdateAccount(valid); err != nil {
		t.Fatalf("expected valid update, got %v", err)
	}

	withPassword := *valid
	withPassword.Password = "secret"
	if err := validateUpdateAccount(&withPassword); err != nil {
		t.Fatalf("expected valid update with password, got %v", err)
	}

	emptyEmail := *valid
	emptyEmail.Email = ""
	if err := validateUpdateAccount(&emptyEmail); err == nil {
		t.Fatal("expected validation error for empty email")
	}
}

func TestValidateTestAccountWithStoredCredentials(t *testing.T) {
	t.Parallel()

	stored := &testAccountRequest{
		AccountID: "550e8400-e29b-41d4-a716-446655440000",
		IMAPHost:  "imap.example.com",
		IMAPPort:  993,
		SMTPHost:  "smtp.example.com",
		SMTPPort:  587,
	}
	if err := validateTestAccount(stored); err != nil {
		t.Fatalf("expected valid test with account_id, got %v", err)
	}

	noCreds := &testAccountRequest{
		IMAPHost: "imap.example.com",
		IMAPPort: 993,
		SMTPHost: "smtp.example.com",
		SMTPPort: 587,
	}
	if err := validateTestAccount(noCreds); err == nil {
		t.Fatal("expected validation error without password or account_id")
	}
}
