Files
2026-05-12 18:49:52 +08:00

75 lines
4.9 KiB
Go

package repository
import (
"context"
"time"
"supply-intelligence/internal/domain"
)
// Repository is the unified persistence interface for all supply-intelligence domain data.
// Concrete implementations: MemoryRepository, PostgresRepository.
type Repository interface {
// Routing State
UpsertRoutingState(ctx context.Context, state domain.AccountRoutingState)
GetRoutingState(ctx context.Context, accountID int64) (domain.AccountRoutingState, bool)
ListRoutingStatesByPlatform(ctx context.Context, platform string) []domain.AccountRoutingState
ListActiveAccounts(ctx context.Context) []domain.AccountRoutingState
// Routing State (context-suffixed aliases for service interfaces)
UpsertRoutingStateContext(ctx context.Context, state domain.AccountRoutingState) domain.AccountRoutingState
GetRoutingStateContext(ctx context.Context, accountID int64) (domain.AccountRoutingState, bool)
// Package Change Events
AppendPackageEvent(ctx context.Context, evt domain.PackageChangeEvent) (domain.PackageChangeEvent, error)
AppendPackageEventContext(ctx context.Context, evt domain.PackageChangeEvent) (domain.PackageChangeEvent, error)
ListPackageEvents(ctx context.Context) []domain.PackageChangeEvent
ListPackageEventsAfter(ctx context.Context, cursor string) ([]domain.PackageChangeEvent, string)
ListRetryablePendingPackageEvents(ctx context.Context, consumer string, now time.Time, limit int) []domain.PackageChangeEvent
GetPackageEventByID(ctx context.Context, eventID string) (domain.PackageChangeEvent, bool)
GetLatestPackageEvent(ctx context.Context, platform, model string) (domain.PackageChangeEvent, bool)
AckPackageEvent(ctx context.Context, eventID, consumer string, result domain.GatewayAckResult, detail string, ackedAt time.Time) (domain.PackageChangeEvent, error)
MarkPackageEventRetry(ctx context.Context, eventID string, retryCount int, nextRetryAt time.Time, category domain.GatewayFailureCategory, detail string, retriedAt time.Time) (domain.PackageChangeEvent, error)
CountPackageEventsBySyncStatus(ctx context.Context, status domain.GatewaySyncStatus) int
CountRetryablePendingPackageEvents(ctx context.Context, consumer string, now time.Time) int
// Gateway Snapshot
UpsertGatewayAppliedSnapshot(ctx context.Context, snapshot domain.GatewayAppliedSnapshot) domain.GatewayAppliedSnapshot
GetGatewayAppliedSnapshot(ctx context.Context, consumer string) (domain.GatewayAppliedSnapshot, bool)
// Discovery Candidates
GetDiscoveryCandidateByID(ctx context.Context, candidateID string) (domain.DiscoveryCandidate, bool)
FindDiscoveryCandidate(ctx context.Context, accountID int64, platform, model string) (domain.DiscoveryCandidate, bool)
GetLatestDiscoveryCandidate(ctx context.Context, platform, model string) (domain.DiscoveryCandidate, bool)
UpsertDiscoveryCandidate(ctx context.Context, candidate domain.DiscoveryCandidate) domain.DiscoveryCandidate
ListDiscoveryCandidates(ctx context.Context, status domain.DiscoveryCandidateStatus) []domain.DiscoveryCandidate
UpdateCandidateStatus(ctx context.Context, candidateID string, status domain.DiscoveryCandidateStatus, failureCode, failureSummary string) error
// Discovery Candidates (context-suffixed aliases for service interfaces)
GetDiscoveryCandidateByIDContext(ctx context.Context, candidateID string) (domain.DiscoveryCandidate, bool)
FindDiscoveryCandidateContext(ctx context.Context, accountID int64, platform, model string) (domain.DiscoveryCandidate, bool)
GetLatestDiscoveryCandidateContext(ctx context.Context, platform, model string) (domain.DiscoveryCandidate, bool)
UpsertDiscoveryCandidateContext(ctx context.Context, candidate domain.DiscoveryCandidate) domain.DiscoveryCandidate
ListDiscoveryCandidatesContext(ctx context.Context, status domain.DiscoveryCandidateStatus) []domain.DiscoveryCandidate
// Supply Packages
UpsertSupplyPackage(ctx context.Context, pkg domain.SupplyPackage) error
GetSupplyPackage(ctx context.Context, platform, model string) (domain.SupplyPackage, bool)
ListSupplyPackages(ctx context.Context, status string) []domain.SupplyPackage
// Probe Execution Logs
AppendProbeExecutionLog(ctx context.Context, log domain.ProbeExecutionLog) error
ListProbeExecutionLogs(ctx context.Context, accountID int64, limit int) ([]domain.ProbeExecutionLog, error)
// Admission Test Logs
AppendAdmissionTestLog(ctx context.Context, candidateID string, status string, failureCode string, failureSummary string, testedAt time.Time) error
ListAdmissionTestLogsByCandidate(ctx context.Context, candidateID string, limit int) ([]domain.AdmissionTestLog, error)
// Supply Accounts
UpsertSupplyAccount(ctx context.Context, account domain.SupplyAccount) domain.SupplyAccount
GetSupplyAccount(ctx context.Context, accountID int64) (domain.SupplyAccount, bool)
ListSupplyAccountsByPlatform(ctx context.Context, platform string) []domain.SupplyAccount
ListSupplyAccounts(ctx context.Context) []domain.SupplyAccount
ListSupplyAccountsByConsumer(ctx context.Context, consumerTag string) []domain.SupplyAccount
}