*/ use HasFactory, HasUuid; protected $fillable = [ 'customer_id', 'order_id', 'host_id', 'vmid', 'guest_ip', 'plan', 'quota_gb', 'traffic_addons', 'disk_gb', 'ram_mb', 'cores', 'subdomain', 'custom_domain', 'nc_admin_ref', 'route_written', 'cert_ok', 'status', 'cancel_requested_at', 'service_ends_at', ]; protected $hidden = ['nc_admin_ref']; protected function casts(): array { return [ 'nc_admin_ref' => 'encrypted', 'route_written' => 'boolean', 'cert_ok' => 'boolean', 'vmid' => 'integer', 'traffic_addons' => 'integer', 'quota_gb' => 'integer', 'disk_gb' => 'integer', 'ram_mb' => 'integer', 'cores' => 'integer', 'cancel_requested_at' => 'datetime', 'service_ends_at' => 'datetime', ]; } /** * Instances that are actually occupying storage on their host. * * A failed instance still holds its disk while its VM exists; a failure * before any VM was created releases it. Kept here rather than written out * at each call site so the host's own accounting and anything reporting on * it cannot drift apart — a dashboard that counted differently from * placement would call a host comfortable while orders were being refused * on it. * * @param \Illuminate\Database\Eloquent\Builder $query */ public function scopeOccupyingHost($query): void { $query->where(fn ($q) => $q->where('status', '!=', 'failed')->orWhereNotNull('vmid')); } public function customer(): BelongsTo { return $this->belongsTo(Customer::class); } public function order(): BelongsTo { return $this->belongsTo(Order::class); } /** * The contract this machine fulfils. The authority on what the customer is * entitled to — the catalogue only describes what we sell today. */ public function subscription(): HasOne { return $this->hasOne(Subscription::class); } public function host(): BelongsTo { return $this->belongsTo(Host::class); } public function dnsRecords(): HasMany { return $this->hasMany(DnsRecord::class); } public function backups(): HasMany { return $this->hasMany(Backup::class); } public function monitoringTargets(): HasMany { return $this->hasMany(MonitoringTarget::class); } public function onboardingTasks(): HasMany { return $this->hasMany(OnboardingTask::class); } }