package model

import (
	"encoding/json"
	"time"
)

// AutomationAction represents a single action in an automation rule.
// Reference: Chatwoot AutomationAction model + P2B M6 spec
type AutomationAction struct {
	ID                uint           `gorm:"primaryKey" json:"id"`
	AutomationRuleID  uint           `gorm:"not null;index" json:"automation_rule_id"`
	ActionType        string         `gorm:"size:100;not null" json:"action_type"` // send_message/update_status/assign_agent/assign_team/add_label/webhook
	ActionParams      json.RawMessage `gorm:"type:jsonb;not null" json:"action_params"`
	CreatedAt         time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt         time.Time      `gorm:"autoUpdateTime" json:"updated_at"`

	AutomationRule AutomationRule `gorm:"foreignKey:AutomationRuleID" json:"automation_rule,omitempty"`
}

func (AutomationAction) TableName() string { return "automation_actions" }