package model import ( "time" "gorm.io/gorm" ) // AssignmentPolicyV2Type defines the type of assignment policy (V2). // Reference: Chatwoot assignment_policies_controller.rb — round_robin, fair, best_skill_match type AssignmentPolicyV2Type string const ( APV2TypeRoundRobin AssignmentPolicyV2Type = "round_robin" APV2TypeFair AssignmentPolicyV2Type = "fair" APV2TypeBestSkillMatch AssignmentPolicyV2Type = "best_skill_match" ) // AssignmentPolicyV2 represents a V2 assignment policy for an account. // Reference: Chatwoot app/models/assignment_policy.rb (V2 spec) // Supports named policies with different assignment strategies, linked to inboxes via AssignmentPolicyInbox. type AssignmentPolicyV2 struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` AccountID uint `gorm:"not null;index;uniqueIndex:idx_apv2_account_name" json:"account_id"` Name string `gorm:"size:255;not null;uniqueIndex:idx_apv2_account_name" json:"name"` Description string `gorm:"type:text" json:"description"` Type AssignmentPolicyV2Type `gorm:"size:50;not null;default:round_robin" json:"type"` CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"` Account Account `gorm:"foreignKey:AccountID" json:"account,omitempty"` AssignmentPolicyInboxes []AssignmentPolicyInbox `gorm:"foreignKey:AssignmentPolicyID" json:"inboxes,omitempty"` } func (AssignmentPolicyV2) TableName() string { return "assignment_policies_v2" } // AssignmentPolicyInbox represents the join between AssignmentPolicyV2 and Inbox. // Each Inbox can only be associated with one AssignmentPolicyV2. // Reference: Chatwoot app/models/assignment_policy_inbox.rb type AssignmentPolicyInbox struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` AssignmentPolicyID uint `gorm:"not null;index" json:"assignment_policy_id"` InboxID uint `gorm:"not null;uniqueIndex:idx_apv2_inbox_unique" json:"inbox_id"` AccountID uint `gorm:"not null;index" json:"account_id"` CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"` AssignmentPolicy AssignmentPolicyV2 `gorm:"foreignKey:AssignmentPolicyID" json:"assignment_policy,omitempty"` Inbox Inbox `gorm:"foreignKey:InboxID" json:"inbox,omitempty"` } func (AssignmentPolicyInbox) TableName() string { return "assignment_policy_inboxes" }