<?php

declare(strict_types=1);

namespace App\Domain\Php\Models;

use App\Domain\Account\Models\Account;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * FPM Pool — per-account PHP-FPM havuzu ayarları.
 *
 * Pool dosyası: /etc/php-fpm.d/<username>_php<version>.conf
 * Sysapi `fpm-pool-tune` bu rowu dosyaya yazar + fpm-reload.
 */
class FpmPool extends Model
{
    protected $table = 'fpm_pools';

    protected $fillable = [
        'account_id',
        'php_version',
        'pm_mode',
        'max_children',
        'start_servers',
        'min_spare_servers',
        'max_spare_servers',
        'max_requests',
        'process_idle_timeout_seconds',
        'request_terminate_timeout_seconds',
        'memory_limit',
        'custom_directives',
        'last_modified_by',
    ];

    /** @var array<string,string> */
    protected $casts = [
        'custom_directives' => 'array',
        'max_children' => 'integer',
        'start_servers' => 'integer',
        'min_spare_servers' => 'integer',
        'max_spare_servers' => 'integer',
        'max_requests' => 'integer',
        'process_idle_timeout_seconds' => 'integer',
        'request_terminate_timeout_seconds' => 'integer',
    ];

    public function account(): BelongsTo
    {
        return $this->belongsTo(Account::class);
    }

    public function modifiedBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'last_modified_by');
    }
}
