package models

import "time"

// PHPPool represents a PHP-FPM pool bound to a panel user.
// Each panel user gets exactly one pool per MVP constraint.
type PHPPool struct {
	ID                             string    `gorm:"type:char(26);primaryKey" json:"id"`
	UserID                         string    `gorm:"type:char(26);not null" json:"user_id"`
	PHPVersion                     string    `gorm:"type:varchar(8);not null" json:"php_version"`
	PmMode                         string    `gorm:"type:varchar(16);not null;default:'ondemand'" json:"pm_mode"`
	PmMaxChildren                  uint32    `gorm:"type:int unsigned;not null;default:20" json:"pm_max_children"`
	ProcessIdleTimeoutSeconds      uint32    `gorm:"type:int unsigned;not null;default:60" json:"process_idle_timeout_seconds"`
	PmStartServers                 uint32    `gorm:"column:pm_start_servers;type:int unsigned;not null;default:2" json:"pm_start_servers"`
	PmMinSpareServers              uint32    `gorm:"column:pm_min_spare_servers;type:int unsigned;not null;default:1" json:"pm_min_spare_servers"`
	PmMaxSpareServers              uint32    `gorm:"column:pm_max_spare_servers;type:int unsigned;not null;default:3" json:"pm_max_spare_servers"`
	PmMaxRequests                  uint32    `gorm:"column:pm_max_requests;type:int unsigned;not null;default:0" json:"pm_max_requests"`
	RequestTerminateTimeoutSeconds uint32    `gorm:"column:request_terminate_timeout_seconds;type:int unsigned;not null;default:0" json:"request_terminate_timeout_seconds"`
	PerformanceMode                string    `gorm:"column:performance_mode;type:varchar(24);not null;default:'balanced'" json:"performance_mode"`
	Status                         string    `gorm:"type:varchar(16);not null;default:'pending'" json:"status"`
	LastError                      *string   `gorm:"type:text" json:"last_error,omitempty"`
	CreatedAt                      time.Time `gorm:"type:datetime(6);not null" json:"created_at"`
	UpdatedAt                      time.Time `gorm:"type:datetime(6);not null" json:"updated_at"`
}

func (PHPPool) TableName() string { return "php_pools" }
