| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package models
- import (
- "time"
- )
- // User is an agent‑or‑human account that can call ERP tools.
- type User struct {
- ID uint `gorm:"primaryKey"`
- Email string `gorm:"size:255;not null;uniqueIndex"`
- Password string `gorm:"size:255;not null"` // hashed password or credential reference
- Roles []Role `gorm:"many2many:user_roles;constraint:OnDelete:CASCADE;"`
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- // Note represents a note belonging to a user and is associated with a Service.
- type Note struct {
- ID uint `gorm:"primaryKey"`
- Title string `gorm:"size:200;not null"` // title of the note
- Content string `gorm:"type:text;not null"` // content body
- // Associations
- UserID uint
- User User `gorm:"foreignKey:UserID"`
- ServiceID uint
- Service Service `gorm:"foreignKey:ServiceID"`
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- // Role groups permissions that can be assigned to users or agents.
- type Role struct {
- ID uint `gorm:"primaryKey"`
- Name string `gorm:"size:100;not null;uniqueIndex"`
- Description string `gorm:"size:255"`
- Permissions []Permission `gorm:"many2many:role_permissions;constraint:OnDelete:CASCADE;"`
- }
- // Permission is a fine‑grained action that can be allowed/denied.
- type Permission struct {
- ID uint `gorm:"primaryKey"`
- Code string `gorm:"size:100;not null;uniqueIndex"` // e.g. "invoice:create"
- Description string `gorm:"size:255"`
- }
- // Service & related entities (agents coordinate work around Services)
- type Service struct {
- ID uint `gorm:"primaryKey"`
- Name string `gorm:"size:200;not null"` // human‑readable Service name
- Description string `gorm:"type:text"`
- // Owner/creator of the Service
- CreatedByID uint
- CreatedBy User `gorm:"foreignKey:CreatedByID"`
- // Participants – many‑to‑many (agents & humans)
- Participants []User `gorm:"many2many:Service_participants;"`
- // Service tasks
- Tasks []Task `gorm:"foreignKey:ServiceID"`
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- // Task management (assignable work items)
- type Task struct {
- ID uint `gorm:"primaryKey"`
- Title string `gorm:"size:200;not null"`
- Content string `gorm:"type:text;not null"`
- // Which service the task belongs to
- ServiceID *uint
- Service *Service `gorm:"foreignKey:ServiceID"`
- // Who created the task
- CreatedByID uint
- CreatedBy User `gorm:"foreignKey:CreatedByID"`
- // Who updated the task
- UpdatedByID uint
- UpdatedBy User `gorm:"foreignKey:UpdatedByID"`
- // Assignment – can be nil (unassigned) or point to a user/agent
- AssigneeID *uint
- Assignee *User `gorm:"foreignKey:AssigneeID"`
- StatusID uint // FK to TaskStatus
- Status TaskStatus `gorm:"foreignKey:StatusID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
- DueDate *time.Time
- Priority string `gorm:"size:20"` // e.g. low/medium/high
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- // Separate table for task status – makes it easy to add custom workflow steps.
- type TaskStatus struct {
- ID uint `gorm:"primaryKey"`
- Code string `gorm:"size:50;not null;uniqueIndex"` // e.g. "open", "in_progress", "done"
- Label string `gorm:"size:100"` // human‑readable label
- // Reverse relation (optional)
- Tasks []Task `gorm:"foreignKey:StatusID"`
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- // Simple chat / messaging between users/agents
- type Channel struct {
- ID uint `gorm:"primaryKey"`
- Title string `gorm:"size:200;not null"`
- // Participants – many‑to‑many (GORM will create the join table automatically)
- Participants []User `gorm:"many2many:conversation_participants;"`
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- // Message sent inside a conversation.
- type Message struct {
- ID uint `gorm:"primaryKey"`
- ConversationID uint `gorm:"index;not null"` // refers to Channel.ID
- SenderID uint `gorm:"index;not null"` // user/agent that authored the message
- Sender User `gorm:"foreignKey:SenderID"`
- Content string `gorm:"type:text;not null"`
- SentAt time.Time `gorm:"autoCreateTime"`
- CreatedAt time.Time
- UpdatedAt time.Time
- }
|