package ga

import "net/url"

//WARNING: This file was generated. Do not edit.

//Item Hit Type
type Item struct {
	iD              string
	name            string
	price           float64
	priceSet        bool
	quantity        int64
	quantitySet     bool
	code            string
	codeSet         bool
	category        string
	categorySet     bool
	currencyCode    string
	currencyCodeSet bool
}

// NewItem creates a new Item Hit Type.
// A unique identifier for the transaction. This value should
// be the same for both the Transaction hit and Items hits
// associated to the particular transaction.
// Specifies the item name.

func NewItem(iD string, name string) *Item {
	h := &Item{
		iD:   iD,
		name: name,
	}
	return h
}

func (h *Item) addFields(v url.Values) error {
	v.Add("ti", h.iD)
	v.Add("in", h.name)
	if h.priceSet {
		v.Add("ip", float2str(h.price))
	}
	if h.quantitySet {
		v.Add("iq", int2str(h.quantity))
	}
	if h.codeSet {
		v.Add("ic", h.code)
	}
	if h.categorySet {
		v.Add("iv", h.category)
	}
	if h.currencyCodeSet {
		v.Add("cu", h.currencyCode)
	}
	return nil
}

// Specifies the price for a single item / unit.
func (h *Item) Price(price float64) *Item {
	h.price = price
	h.priceSet = true
	return h
}

// Specifies the number of items purchased.
func (h *Item) Quantity(quantity int64) *Item {
	h.quantity = quantity
	h.quantitySet = true
	return h
}

// Specifies the SKU or item code.
func (h *Item) Code(code string) *Item {
	h.code = code
	h.codeSet = true
	return h
}

// Specifies the category that the item belongs to.
func (h *Item) Category(category string) *Item {
	h.category = category
	h.categorySet = true
	return h
}

// When present indicates the local currency for all transaction
// currency values. Value should be a valid ISO 4217 currency
// code.
func (h *Item) CurrencyCode(currencyCode string) *Item {
	h.currencyCode = currencyCode
	h.currencyCodeSet = true
	return h
}

func (h *Item) Copy() *Item {
	c := *h
	return &c
}
