package channel

import (
	"time"

	"github.com/gochat/gochat/internal/model"
)

// ChannelAPI represents a REST API channel configuration.
// Reference: Chatwoot Channel::Api + P2B M2 spec
type ChannelAPI struct {
	ID           uint      `gorm:"primaryKey" json:"id"`
	InboxID      uint      `gorm:"uniqueIndex;not null" json:"inbox_id"`
	WebhookURL   string    `gorm:"size:512" json:"webhook_url"`
	HMACToken    string    `gorm:"size:255" json:"hmac_token"`
	Identifier   string    `gorm:"size:255" json:"identifier"`
	CreatedAt    time.Time `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt    time.Time `gorm:"autoUpdateTime" json:"updated_at"`

	Inbox model.Inbox `gorm:"foreignKey:InboxID" json:"inbox,omitempty"`
}

func (ChannelAPI) TableName() string { return "channel_api" }
func (c ChannelAPI) GetInboxID() uint                    { return c.InboxID }
func (c ChannelAPI) GetChannelType() model.InboxChannelType { return model.InboxChannelTypeApi }