package vo

import "fmt"

// OrderSide is a value object representing the side of an order (buy or sell).
type OrderSide string

const (
	Buy  OrderSide = "buy"
	Sell OrderSide = "sell"
)

// ValidOrderSides lists all valid OrderSide values.
var ValidOrderSides = []OrderSide{Buy, Sell}

// NewOrderSide creates a validated OrderSide from a string.
func NewOrderSide(s string) (OrderSide, error) {
	side := OrderSide(s)
	if side != Buy && side != Sell {
		return "", fmt.Errorf("invalid order side: %q, must be 'buy' or 'sell'", s)
	}
	return side, nil
}

// String returns the string representation of the OrderSide.
func (s OrderSide) String() string {
	return string(s)
}

// IsValid returns true if the OrderSide is a recognized value.
func (s OrderSide) IsValid() bool {
	return s == Buy || s == Sell
}

// Opposite returns the opposite side.
func (s OrderSide) Opposite() OrderSide {
	if s == Buy {
		return Sell
	}
	return Buy
}
