<?php

namespace App\Models\Pivot;

use App\Support\Tenant;
use Illuminate\Database\Eloquent\Relations\Pivot;

/**
 * Pivot custom para employee_services. Auto-rellena company_id desde el tenant
 * activo cuando se crea un registro.
 */
class EmployeeServicePivot extends Pivot
{
    protected $table = 'employee_services';

    public $incrementing = true;

    public static function boot(): void
    {
        parent::boot();

        static::creating(function ($pivot) {
            if (! $pivot->company_id && Tenant::check()) {
                $pivot->company_id = Tenant::id();
            }
        });
    }
}
