Record Class Service

java.lang.Object
java.lang.Record
com.tnsai.payment.Service
Record Components:
name - canonical service identifier ("github.create_pr", "embed.text")
unit - billing unit ("request", "1k_tokens", "second", "byte")
quantity - quantity of unit; brokers multiply by their per-unit price
expectedPriceUSD - optional caller-side price expectation in USD; the broker cross-checks against its policy and fails the PaymentBroker.quote(com.tnsai.identity.AgentPrincipal, com.tnsai.identity.AgentPrincipal, com.tnsai.payment.Service) when the spread is too wide
metadata - free-form annotations the broker may use (region, urgency, …); never carries sensitive payload

public record Service(String name, String unit, BigDecimal quantity, Optional<BigDecimal> expectedPriceUSD, Map<String,String> metadata) extends Record
Description of a unit-of-work an agent offers (TNS-298). The PaymentBroker uses it to derive a Quote between a payer and a payee.

Pricing is the broker's concern, not this record's. The fields here describe what is being paid for; the broker decides how much based on the payee's price list, the payer's subscription, market rates (for x402-style settlement), or any other policy the broker implements.

Since:
0.10.0 (TNS-298)
  • Constructor Details

    • Service

      public Service(String name, String unit, BigDecimal quantity, Optional<BigDecimal> expectedPriceUSD, Map<String,String> metadata)
      Creates an instance of a Service record class.
      Parameters:
      name - the value for the name record component
      unit - the value for the unit record component
      quantity - the value for the quantity record component
      expectedPriceUSD - the value for the expectedPriceUSD record component
      metadata - the value for the metadata record component
  • Method Details

    • 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.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • unit

      public String unit()
      Returns the value of the unit record component.
      Returns:
      the value of the unit record component
    • quantity

      public BigDecimal quantity()
      Returns the value of the quantity record component.
      Returns:
      the value of the quantity record component
    • expectedPriceUSD

      public Optional<BigDecimal> expectedPriceUSD()
      Returns the value of the expectedPriceUSD record component.
      Returns:
      the value of the expectedPriceUSD record component
    • metadata

      public Map<String,String> metadata()
      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component