<?php

declare(strict_types=1);

namespace Builder\Seo\Models;

use Builder\Seo\Enums\RedirectType;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;

/**
 * @property int $id
 * @property string $from
 * @property string $to
 * @property RedirectType $type
 */
final class Redirect extends Model
{
    protected $fillable = ['from', 'to', 'type'];

    protected function casts(): array
    {
        return ['type' => RedirectType::class];
    }

    /** @return Attribute<string, string> */
    protected function from(): Attribute
    {
        return Attribute::make(
            set: fn (string $value): string => '/'.rtrim(ltrim($value, '/'), '/'),
        );
    }
}
