<?php

declare(strict_types=1);

namespace App\Administration\Domain\Model\SchoolBranding;

use App\Administration\Domain\Exception\LogoUrlInvalideException;

use const FILTER_VALIDATE_URL;

use function filter_var;
use function str_starts_with;

/**
 * Value Object représentant l'URL du logo d'un établissement.
 *
 * Contraintes :
 * - URL valide
 * - Schéma HTTP ou HTTPS uniquement
 */
final readonly class LogoUrl
{
    public string $value;

    public function __construct(string $value)
    {
        if (filter_var($value, FILTER_VALIDATE_URL) === false) {
            throw LogoUrlInvalideException::pourUrl($value);
        }

        if (!str_starts_with($value, 'http://') && !str_starts_with($value, 'https://')) {
            throw LogoUrlInvalideException::pourUrl($value);
        }

        $this->value = $value;
    }

    public function equals(self $other): bool
    {
        return $this->value === $other->value;
    }

    public function __toString(): string
    {
        return $this->value;
    }
}
