<?php

declare(strict_types=1);

namespace FreshCloud\Mail\ImapClient;

final readonly class ImapCredentials
{
    public function __construct(
        public string $host,
        public int $port,
        public string $username,
        public string $password,
        public string $encryption = 'none',
        public string $userId = '',
        public string $accountId = ''
    ) {
        $this->validate();
    }

    private function validate(): void
    {
        if ($this->host === '') {
            throw new ImapException('Host cannot be empty');
        }

        if ($this->port < 1 || $this->port > 65535) {
            throw new ImapException('Port must be between 1 and 65535');
        }

        if (!in_array($this->encryption, ['tls', 'ssl', 'starttls', 'none'], true)) {
            throw new ImapException('Encryption must be one of: tls, ssl, starttls, none');
        }
    }
}