package db

import "time"

// RepositoryWebhookFanout freezes one durable repository event's exact
// subscriber/request snapshot before any per-hook delivery row is created.
// TargetsJSON contains final URL, transport, headers, and body values; it
// never stores the subscriber's raw configuration or signing secret.
// It is removed with the owning repository push outbox row after every
// required delivery has been atomically materialized.
type RepositoryWebhookFanout struct {
	ID           uint   `gorm:"primaryKey;autoIncrement"`
	RepositoryID uint   `gorm:"not null;index"`
	OperationID  string `gorm:"size:64;not null;uniqueIndex:idx_repository_webhook_fanout_operation_event,priority:1;index"`
	EventKey     string `gorm:"size:512;not null;uniqueIndex:idx_repository_webhook_fanout_operation_event,priority:2"`
	Event        string `gorm:"size:64;not null"`
	Action       string `gorm:"size:64"`
	PayloadJSON  LargeText
	TargetsJSON  LargeText
	State        string `gorm:"size:16;not null"`
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

func (RepositoryWebhookFanout) TableName() string {
	return "repository_webhook_fanouts"
}
