// Package examples 提供课程的可运行领域示例，不包含持久化或生产协议。
package examples

import "errors"

type Money struct {
	cents    int64
	currency string
}

func NewMoney(cents int64, currency string) (Money, error) {
	if cents < 0 || currency == "" {
		return Money{}, errors.New("invalid money")
	}
	return Money{
		cents:    cents,
		currency: currency,
	}, nil
}

type Order struct {
	status string
}

func (order *Order) Cancel() error {
	if order.status == "SHIPPED" {
		return errors.New("already shipped")
	}
	order.status = "CANCELED"
	return nil
}
