<?php

declare(strict_types=1);

namespace Rowbot\Idna;

class IdnaResult
{
    /**
     * @var string
     */
    protected string $domain;

    /**
     * @var int-mask-of<\Rowbot\Idna\Idna::ERROR_*>
     */
    protected int $errors;

    protected bool $transitionalDifferent;

    public function __construct(string $domain, DomainInfo $info)
    {
        $this->domain = $domain;
        $this->errors = $info->getErrors();
        $this->transitionalDifferent = $info->isTransitionalDifferent();
    }

    public function getDomain(): string
    {
        return $this->domain;
    }

    public function getErrors(): int
    {
        return $this->errors;
    }

    public function hasError(int $error): bool
    {
        return ($this->errors & $error) !== 0;
    }

    public function hasErrors(): bool
    {
        return $this->errors !== 0;
    }

    public function isTransitionalDifferent(): bool
    {
        return $this->transitionalDifferent;
    }
}
