package model

import (
	"encoding/json"
	"time"
)

// AgentCapacityPolicy defines agent capacity and assignment rules.
// Reference: Chatwoot AgentCapacityPolicy + P2B M1 spec
type AgentCapacityPolicy struct {
	ID              uint           `gorm:"primaryKey" json:"id"`
	AccountID       uint           `gorm:"not null;index" json:"account_id"`
	Name            string         `gorm:"size:255;not null" json:"name"`
	AssignmentLogic string         `gorm:"size:50" json:"assignment_logic"` // round_robin/least_busy
	ExclusionRules  json.RawMessage `gorm:"type:jsonb" json:"exclusion_rules"`
	CreatedAt       time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt       time.Time      `gorm:"autoUpdateTime" json:"updated_at"`

	Account      Account       `gorm:"foreignKey:AccountID" json:"account,omitempty"`
	AccountUsers []AccountUser `gorm:"foreignKey:AgentCapacityID" json:"account_users,omitempty"`
}

func (AgentCapacityPolicy) TableName() string { return "agent_capacity_policies" }