<?php

namespace Maestro\Core\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;

/**
 * Singleton company profile fields aligned with Top-Level-Punt organization_settings.
 *
 * @property-read Carbon|null $updated_at
 */
class Organization extends Model
{
    use LogsActivity;

    /**
     * @var list<string>
     */
    protected $fillable = [
        'name',
        'company_name',
        'street',
        'house_number',
        'address_line_1',
        'address_line_2',
        'city',
        'region',
        'postal_code',
        'country_code',
        'country',
        'website',
        'phone',
        'email',
        'invoice_email',
        'kvk_number',
        'vat_number',
        'iban',
        'contact_name',
    ];

    /**
     * @return HasMany<User, Organization>
     */
    public function users(): HasMany
    {
        return $this->hasMany(User::class);
    }

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logOnly($this->fillable)
            ->logOnlyDirty()
            ->useLogName('organization');
    }

    /** Display / legal label (TLP uses company_name; legacy uses name). */
    public function getDisplayNameAttribute(): string
    {
        return (string) ($this->company_name ?: $this->name);
    }
}
