<?php

declare(strict_types=1);

namespace App\Domain\Redirect\Models;

use App\Domain\Account\Models\Account;
use App\Domain\Domain\Models\Domain;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Redirect extends Model
{
    use SoftDeletes;

    protected $table = 'redirects';

    protected $fillable = [
        'account_id', 'domain_id', 'source_path', 'target_url',
        'type', 'keep_query_string', 'case_sensitive', 'is_wildcard', 'is_active',
    ];

    protected function casts(): array
    {
        return [
            'keep_query_string' => 'boolean',
            'case_sensitive' => 'boolean',
            'is_wildcard' => 'boolean',
            'is_active' => 'boolean',
        ];
    }

    public function account(): BelongsTo
    {
        return $this->belongsTo(Account::class);
    }

    public function domain(): BelongsTo
    {
        return $this->belongsTo(Domain::class);
    }
}
