<?php

namespace App\Models;

use App\Models\Concerns\HasUuid;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Datacenter extends Model
{
    /** @use HasFactory<\Database\Factories\DatacenterFactory> */
    use HasFactory, HasUuid;

    protected $fillable = ['code', 'name', 'facility', 'location', 'active', 'next_host_number'];

    protected function casts(): array
    {
        return ['active' => 'boolean', 'next_host_number' => 'integer'];
    }

    public function scopeActive(Builder $query): Builder
    {
        return $query->where('active', true);
    }

    public function hosts()
    {
        return $this->hasMany(Host::class, 'datacenter', 'code');
    }
}
