package strategy import "git.mleku.dev/mleku/dendrite/pkg/axiom" // StrategyConstraint defines a lattice site that accepts strategy elements // of a specific category and minimum granularity level. // Implements axiom.Constraint and axiom.LayeredConstraint. type StrategyConstraint struct { Cat Category MinLevel Level } // Tag returns "strategy:". func (c StrategyConstraint) Tag() string { return "strategy:" + c.Cat.String() } // Admits returns true for StrategyElements of matching category and // sufficient granularity. func (c StrategyConstraint) Admits(e axiom.Element) bool { se, ok := e.(StrategyElement) if !ok { return false } return se.Cat == c.Cat && se.Lvl >= c.MinLevel } // Layer returns the strategy layer. func (c StrategyConstraint) Layer() axiom.Layer { return axiom.Layer{Name: "strategy", Depth: int(c.MinLevel)} } // Aligns checks that a layered element is in the strategy layer. func (c StrategyConstraint) Aligns(le axiom.LayeredElement) bool { return le.Layer().Name == "strategy" } // CategoryConstraint is a broader constraint accepting any strategy element // regardless of category. Used for cross-chapter bridge sites. type CategoryConstraint struct{} // Tag returns "strategy". func (CategoryConstraint) Tag() string { return "strategy" } // Admits returns true for any StrategyElement. func (CategoryConstraint) Admits(e axiom.Element) bool { _, ok := e.(StrategyElement) return ok } // Verify interface compliance. var ( _ axiom.Constraint = StrategyConstraint{} _ axiom.LayeredConstraint = StrategyConstraint{} _ axiom.Constraint = CategoryConstraint{} )