package judgement import ( "context" "errors" "github.com/samcharles93/archie-core/modules/connectors" ) // Reversibility sets a ceiling from whether the action can be undone, as the // connector declares it. type Reversibility struct{} // Name is the guard's name in verdicts. func (Reversibility) Name() string { return "reversibility" } // Advisory is false: the declaration is data, not a model's opinion. func (Reversibility) Advisory() bool { return false } // Judge maps the declared reversibility to a ceiling. An action that declares // none lacks the evidence this guard needs. func (Reversibility) Judge(_ context.Context, a Action) (Verdict, error) { switch { case a.Effect.ReadOnly: return Verdict{Ceiling: ActQuietly}, nil case a.Effect.Reversibility == connectors.UndoneAutomatically: return Verdict{Ceiling: ActQuietly, Findings: []Finding{{Text: "undone automatically"}}}, nil case a.Effect.Reversibility == connectors.Recoverable || a.Target.Disposable: return Verdict{Ceiling: ActAndTell, Findings: []Finding{{Text: "recoverable, or the target is disposable"}}}, nil case a.Effect.Reversibility == connectors.Irreversible: return Verdict{Ceiling: ProposeAndWait, Findings: []Finding{{Text: "irreversible"}}}, nil } return Verdict{}, errors.New("the connector declares no reversibility for this action") } // Precedent sets a ceiling from the action class's earned level. Until a // class has history, it is the fresh-install default: read-only classes act // quietly, every other class proposes and waits. type Precedent struct{} // Name is the guard's name in verdicts. func (Precedent) Name() string { return "precedent" } // Advisory is false. func (Precedent) Advisory() bool { return false } // Judge returns the class's level. func (Precedent) Judge(_ context.Context, a Action) (Verdict, error) { if a.Effect.ReadOnly { return Verdict{Ceiling: ActQuietly}, nil } return Verdict{Ceiling: ProposeAndWait, Findings: []Finding{{Text: "this action class has no approvals yet"}}}, nil }