Files
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

53 lines
1.0 KiB
Go

package rule
import (
"github.com/hanzoai/commerce/models/discount/action"
"github.com/hanzoai/commerce/models/discount/trigger"
"github.com/hanzoai/commerce/models/types/currency"
)
// Quantity-based trigger
type Quantity struct {
Start int `json:"start,omitempty"`
}
// Price-based trigger
type Price struct {
Start currency.Cents `json:"start,omitempty"`
}
// Union of possible triggers
type Trigger struct {
Price Price `json:"price,omitempty"`
Quantity Quantity `json:"quantity,omitempty"`
}
// Determine type of trigger
func (t Trigger) Type() trigger.Type {
if t.Quantity.Start > 0 {
return trigger.Quantity
}
if t.Price.Start > 0 {
return trigger.Price
}
panic("Invalid trigger type for discount rule")
}
// Discount action
type Discount struct {
Flat currency.Cents `json:"flat,omitempty"`
Percent float64 `json:"percent,omitempty"`
}
// Union of possible actions
type Action struct {
Discount
}
// Determine type of action
func (a Action) Type() action.Type {
return action.Discount
}