Polygon::class, ]; } protected static function booted(): void { static::creating(function (self $tenant): void { if (empty($tenant->uuid)) { $tenant->uuid = (string) Str::uuid(); } if (empty($tenant->code) && ! empty($tenant->name)) { $tenant->code = static::deriveCode($tenant->name); } }); } /** * PSGC-derived tenant code. We use the city/municipality's `code` * field when linked, otherwise slugify the name. Always uppercase. */ public static function deriveCode(string $name, ?CityMunicipality $city = null): string { if ($city?->code) { return strtoupper($city->code); } return strtoupper(Str::slug($name)); } public function cityMunicipality(): BelongsTo { return $this->belongsTo(CityMunicipality::class); } public function users(): HasMany { return $this->hasMany(User::class); } public function households(): HasMany { return $this->hasMany(Household::class); } public function trucks(): HasMany { return $this->hasMany(Truck::class); } public function isActive(): bool { return $this->status === self::STATUS_ACTIVE; } /** * Effective area: the explicit boundary override if set, else the * linked municipality. Used by geo lookups. */ public function effectiveBoundary(): ?Polygon { return $this->boundary_polygon; } public function getRouteKeyName(): string { return 'uuid'; } public function getQrPriceAttribute(): float { return $this->qr_retail_price_centavos / 100; } }