package store

import (
	"context"

	"switchboard-core/models"
)

// ExtensionPermissionStore manages declared and granted permissions for packages.
type ExtensionPermissionStore interface {
	// DeclareForPackage upserts the declared permissions from a manifest.
	// Any permissions in the DB for this package that are NOT in the
	// provided list are deleted (manifest is the source of truth).
	// Existing grants are preserved on upsert.
	DeclareForPackage(ctx context.Context, packageID string, permissions []string) error

	// ListForPackage returns all declared permissions for a package.
	ListForPackage(ctx context.Context, packageID string) ([]models.ExtensionPermission, error)

	// GrantedForPackage returns only granted permissions for a package.
	// Used at runtime to determine which modules to inject.
	GrantedForPackage(ctx context.Context, packageID string) ([]string, error)

	// Grant marks a permission as granted by an admin.
	Grant(ctx context.Context, packageID, permission, grantedBy string) error

	// Revoke removes a grant (sets granted=false).
	Revoke(ctx context.Context, packageID, permission string) error

	// GrantAll grants all declared permissions for a package.
	GrantAll(ctx context.Context, packageID, grantedBy string) error

	// DeleteForPackage removes all permission rows for a package.
	// Called when a package is uninstalled.
	DeleteForPackage(ctx context.Context, packageID string) error
}
