Record Class CostScope

java.lang.Object
java.lang.Record
com.tnsai.quality.cost.CostScope

public record CostScope(String tenantId, Optional<String> agentId, Optional<String> capabilityId) extends Record
Per-spend scope key — a (tenantId, agentId, capabilityId) triple used by CostBudgetStore to bucket recorded spend (issue #82).

The store tracks spend at the finest scope it sees and rolls up for budgets defined at coarser scopes. Caller hands a fully-populated scope on CostBudgetStore.record(com.tnsai.quality.cost.CostScope, java.math.BigDecimal); lookup queries match by exact scope OR by any prefix subset that satisfies the budget's scope filter.

Since:
0.5.0 (issue #82)
  • Constructor Details

    • CostScope

      public CostScope(String tenantId, Optional<String> agentId, Optional<String> capabilityId)
      Creates an instance of a CostScope record class.
      Parameters:
      tenantId - the value for the tenantId record component
      agentId - the value for the agentId record component
      capabilityId - the value for the capabilityId record component
  • Method Details

    • tenant

      public static CostScope tenant(String tenantId)
      Convenience: tenant-only scope (no agent / capability narrowing).
    • agent

      public static CostScope agent(String tenantId, String agentId)
      Convenience: tenant + agent scope.
    • full

      public static CostScope full(String tenantId, String agentId, String capabilityId)
      Convenience: full tenant + agent + capability scope.
    • contains

      public boolean contains(CostScope other)
      true when other falls within this scope — i.e. this scope's populated fields all match other's. Used by CostBudgetStore to roll up finer-scoped spend records into coarser-scoped budgets.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • tenantId

      public String tenantId()
      Returns the value of the tenantId record component.
      Returns:
      the value of the tenantId record component
    • agentId

      public Optional<String> agentId()
      Returns the value of the agentId record component.
      Returns:
      the value of the agentId record component
    • capabilityId

      public Optional<String> capabilityId()
      Returns the value of the capabilityId record component.
      Returns:
      the value of the capabilityId record component