105 lines
4.2 KiB
Go
105 lines
4.2 KiB
Go
package outbound
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"lincodex/backend/internal/domain"
|
|
)
|
|
|
|
// ErrDemoTrainingBindingMismatch reports that the published families of the
|
|
// express training category do not match the binding the seed asked for.
|
|
var ErrDemoTrainingBindingMismatch = errors.New("demo training binding does not match the published families")
|
|
|
|
// DemoAccountCensus counts the accounts of a stand by whether their address
|
|
// belongs to the reserved synthetic demo domain. It holds counts only.
|
|
type DemoAccountCensus struct {
|
|
Total int64
|
|
Synthetic int64
|
|
}
|
|
|
|
// Ordinary is the number of accounts outside the synthetic demo domain.
|
|
func (census DemoAccountCensus) Ordinary() int64 { return census.Total - census.Synthetic }
|
|
|
|
// DemoTrainingBinding is the express training binding that the demo seed
|
|
// stores for the current product policy. The binding pins every published
|
|
// family of the training category, which must match ItemCount.
|
|
type DemoTrainingBinding struct {
|
|
Category string
|
|
PolicyVersionID domain.PolicyVersionID
|
|
ItemCount int
|
|
ReviewedBy domain.AssessmentOperator
|
|
}
|
|
|
|
// DemoInventory counts the records that the demo seed creates or relies on.
|
|
// Two seed runs on the same stand must report the same inventory. It holds
|
|
// counts only, never a personal value.
|
|
type DemoInventory struct {
|
|
SyntheticAccounts int64
|
|
VerifiedSynthetic int64
|
|
Organizations int64
|
|
Memberships int64
|
|
ConsentRecords int64
|
|
CandidateProfiles int64
|
|
Questionnaires int64
|
|
Attempts int64
|
|
AttemptResults int64
|
|
CurrentCategories int64
|
|
EvidenceFacts int64
|
|
PublishedCards int64
|
|
ProductPolicyVersions int64
|
|
PublishedFamilies int64
|
|
CategoryOpenings int64
|
|
CategoryAttestations int64
|
|
TrainingBindings int64
|
|
OrdinaryAccounts int64
|
|
TotalAccounts int64
|
|
SyntheticAccountDomain string
|
|
}
|
|
|
|
// DemoSeedStore holds the few storage operations of the demo seed that no
|
|
// product port covers: an account census, the current category of one
|
|
// candidate, the express training binding, and an inventory of counts. Every
|
|
// method runs in its own statement or transaction; none reads or returns a
|
|
// personal value.
|
|
type DemoSeedStore interface {
|
|
// CountAccounts counts all accounts and those whose address ends with
|
|
// "@" plus syntheticDomain.
|
|
CountAccounts(ctx context.Context, syntheticDomain string) (DemoAccountCensus, error)
|
|
|
|
// CurrentCategoryAttempt returns the attempt behind the candidate's
|
|
// current assessment category of the specialization, and false when the
|
|
// candidate holds no such category.
|
|
CurrentCategoryAttempt(
|
|
ctx context.Context,
|
|
candidateID uuid.UUID,
|
|
specialization domain.SpecializationCode,
|
|
) (domain.AssessmentAttemptID, bool, error)
|
|
|
|
// TrainingBindingExists reports whether the category already has a
|
|
// training binding for the policy version.
|
|
TrainingBindingExists(ctx context.Context, category string, policyVersionID domain.PolicyVersionID) (bool, error)
|
|
|
|
// BindTrainingBank stores the binding of every published family of the
|
|
// training category in one transaction. The database checks that the
|
|
// category is disjoint from real openings and that the policy is current.
|
|
// It returns ErrDemoTrainingBindingMismatch when the published family
|
|
// count differs from ItemCount.
|
|
BindTrainingBank(ctx context.Context, binding DemoTrainingBinding) error
|
|
|
|
// AdvanceCandidateOnboarding sets the saved onboarding step of a verified
|
|
// candidate to candidate_assessment, the step that a saved questionnaire
|
|
// leaves, when the step is still an earlier candidate step and the
|
|
// questionnaire is saved. No product transition moves the consent step,
|
|
// and the profile and questionnaire transitions apply only from their own
|
|
// step, so a stand whose rows were saved earlier needs this statement. It
|
|
// never moves a later step back, and it reports whether it changed the step.
|
|
AdvanceCandidateOnboarding(ctx context.Context, userID uuid.UUID, at time.Time) (bool, error)
|
|
|
|
// Inventory counts the seed's records on the stand.
|
|
Inventory(ctx context.Context, syntheticDomain string, categories []string) (DemoInventory, error)
|
|
}
|