<?php

namespace App\Domains\Domain\Models;

use App\Domains\Workspace\Models\Workspace;
use Database\Factories\DomainFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Domain extends Model
{
    /** @use HasFactory<DomainFactory> */
    use HasFactory;

    protected $guarded = ['id'];

    protected $casts = [
        'verified_at' => 'datetime',
        'ssl_issued_at' => 'datetime',
        'ssl_expires_at' => 'datetime',
        'is_default' => 'boolean',
    ];

    /** @return BelongsTo<Workspace, $this> */
    public function workspace(): BelongsTo
    {
        return $this->belongsTo(Workspace::class);
    }

    public function isVerified(): bool
    {
        return $this->verified_at !== null;
    }

    protected static function newFactory(): DomainFactory
    {
        return DomainFactory::new();
    }
}
