package store

import (
	"context"
	"time"

	"switchboard-core/models"
)

// TriggerStore manages extension-declared event and webhook triggers.
type TriggerStore interface {
	// CRUD
	Create(ctx context.Context, t *models.Trigger) error
	GetByID(ctx context.Context, id string) (*models.Trigger, error)
	Update(ctx context.Context, t *models.Trigger) error
	Delete(ctx context.Context, id string) error

	// Queries
	List(ctx context.Context, opts TriggerListOptions) ([]models.Trigger, int, error)
	ListByPackage(ctx context.Context, packageID string) ([]models.Trigger, error)
	ListEnabledByType(ctx context.Context, triggerType string) ([]models.Trigger, error)

	// Lifecycle
	SetEnabled(ctx context.Context, id string, enabled bool) error
	UpdateFireState(ctx context.Context, id string, lastFireAt time.Time, lastError string) error

	// Webhook resolution
	GetWebhook(ctx context.Context, packageID, slug string) (*models.Trigger, error)

	// Cleanup
	DeleteForPackage(ctx context.Context, packageID string) error

	// Logs
	LogExecution(ctx context.Context, log *models.TriggerLog) error
	ListLogs(ctx context.Context, triggerID string, limit int) ([]models.TriggerLog, error)
	PruneLogs(ctx context.Context, before time.Time) (int64, error)
}

// TriggerListOptions provides filtering for trigger list queries.
type TriggerListOptions struct {
	ListOptions
	PackageID string
	Type      string
	Enabled   *bool
}
