*/ use HasFactory; /** Reminder and summary defaults: repeat nothing, a daily summary from 7 a.m., the weekly one on Mondays. */ protected $attributes = [ 'reminder_interval_days' => 0, 'digest_daily' => true, 'digest_weekly' => false, 'digest_weekday' => 1, 'digest_hour' => 7, 'digest_when_empty' => false, ]; /** * The landlord the existing single-website data belongs to. */ public static function stommer(): self { return static::query()->firstOrCreate( ['slug' => 'stommer'], ['name' => 'Stommer'] + TenantDefaults::forLegacyLandlord(encryptBank: false), ); } /** * @return array */ protected function casts(): array { return [ 'is_active' => 'boolean', 'bank_account_holder' => 'encrypted', 'bank_iban' => 'encrypted', 'bank_bic' => 'encrypted', 'bank_name' => 'encrypted', 'tax_note' => 'encrypted', 'mailbox_password' => 'encrypted', 'reminder_interval_days' => 'integer', 'digest_daily' => 'boolean', 'digest_weekly' => 'boolean', 'digest_weekday' => 'integer', 'digest_hour' => 'integer', 'digest_sections' => 'array', 'process_defaults' => 'array', 'document_releases' => 'array', 'digest_when_empty' => 'boolean', 'digest_daily_sent_on' => 'immutable_date', 'digest_weekly_sent_on' => 'immutable_date', ]; } /** * @return HasMany */ public function sites(): HasMany { return $this->hasMany(Site::class); } /** * @return HasMany */ public function properties(): HasMany { return $this->hasMany(Property::class); } /** * @return HasMany */ public function services(): HasMany { return $this->hasMany(TenantService::class); } /** * @return HasMany */ public function serviceUsages(): HasMany { return $this->hasMany(ServiceUsage::class); } /** * The mailbox this landlord reads portal notifications from, or null when they have none. An empty * host means the fast path is simply off for them. * * @return array{host: string, port: int, encryption: string, username: string, password: ?string, folder: string}|null */ public function mailbox(): ?array { if (blank($this->mailbox_host) || blank($this->mailbox_username)) { return null; } return [ 'host' => (string) $this->mailbox_host, 'port' => (int) ($this->mailbox_port ?: 993), 'encryption' => (string) ($this->mailbox_encryption ?: 'ssl'), 'username' => (string) $this->mailbox_username, 'password' => $this->mailbox_password, 'folder' => (string) ($this->mailbox_folder ?: 'INBOX'), ]; } public function isLive(): bool { return $this->operating_mode === 'live'; } /** * Notification addresses of this landlord. * * @return list */ public function notificationRecipients(): array { return Settings::addressList($this->notification_emails); } /** * @return BelongsToMany */ public function users(): BelongsToMany { return $this->belongsToMany(User::class)->withPivot('role')->withTimestamps(); } }