package models import ( "time" "gorm.io/gorm" ) // DBParticipant is a model that stores raw 'participant' payloads from GenesysCloud websockets and API requests. // // - The ExtractLive function handles the conversion from JSON data (map) into formatted JSON string for websocket payloads. // - The ExtractWithoutAttributes function handles the conversion from JSON data (map) into formatted JSON string for gcq-details requests. // // Table Schema: // // Primary Key: Id // Indexes: ConnectedTime, ConversationId, EndTime, Id, Name, Purpose // JSON Fields: Attributes, MediaRoles, Wrapup // // GORM Specifics: // - Can be preloaded with Sessions []DBSession // - Can be preloaded with Calls []DBCall // - Can be preloaded with User *GCUser // - BeforeSave function, converts UserId into 'nil' if an empty string is returned, this prevents foreign key violations. type DBParticipant struct { Address *string Attributes *string `gorm:"type:json"` ConnectedTime *time.Time `gorm:"index"` ConversationId string `gorm:"foreignKey;index"` EndTime *time.Time `gorm:"index"` ExternalContactId *string ExternalContactInitialDivisionId *string Id string `gorm:"primaryKey;index"` MediaRoles *string `gorm:"type:json"` Name *string `gorm:"index"` Purpose *string `gorm:"index"` QueueId *string UserId *string Wrapup *string `gorm:"type:json"` WrapupExpected *bool WrapupRequired *bool Sessions []DBSession `gorm:"foreignKey:ParticipantId;references:Id"` Calls []DBCall `gorm:"foreignKey:ParticipantId;references:Id"` User *GCUser `gorm:"foreignKey:UserId;references:Id"` } func (DBParticipant) TableName() string { return "gc_participants" } func (p *DBParticipant) BeforeSave(tx *gorm.DB) error { // Convert empty string to nil if p.UserId != nil && *p.UserId == "" { p.UserId = nil } return nil }