package model

import "fmt"

type Weight int64

const (
	Milligrams Weight = 1
	Grams      Weight = Milligrams * 1000
	Kilogram   Weight = Grams * 1000
	Tons       Weight = Kilogram * 1000
)

func (w Weight) String() string {

	switch {
	case w > Tons:
		return fmt.Sprintf("%d t", w/Tons)
	case w > Kilogram:
		return fmt.Sprintf("%d kg", w/Kilogram)
	case w > Grams:
		return fmt.Sprintf("%d g", w/Grams)
	default:
		return fmt.Sprintf("%d mg", w)
	}

}
