package user

import "strconv"

type ItemUser struct {
	// Data
	Data interface{} `json:"data"`

	// EmailAddresses
	EmailAddresses []string `json:"emailaddresses"`

	// Username
	Username string `json:"username"`
}

type ItemAudit struct {
	// Call
	Call string `json:"Call"`

	// Response time
	ResponseTime ResponseTime `json:"Response Time"`

	// StatusCode
	StatusCode StatusCode `json:"Status Code"`

	// Guid
	GUID string `json:"Guid"`

	// Time
	Time float64 `json:"Time"`
}

type ListAudits struct {
	// Data
	Data []ItemAudit `json:"data"`

	// Entry count
	EntryCount uint64 `json:"entryCount"`
}

type ResponseTime float64

func (r *ResponseTime) UnmarshalJSON(b []byte) error {
	if string(b) == "null" {
		*r = ResponseTime(-1)

		return nil
	}

	res, err := strconv.ParseFloat(string(b), 64)
	if err != nil {
		return err
	}

	*r = ResponseTime(res)

	return nil
}

type StatusCode int64

func (s *StatusCode) UnmarshalJSON(b []byte) error {
	if string(b) == "null" {
		*s = StatusCode(-1)

		return nil
	}

	res, err := strconv.ParseInt(string(b), 10, 64)
	if err != nil {
		return err
	}

	*s = StatusCode(res)

	return nil
}

type BriefResources struct {
	Accounts Accounts `json:"Accounts,omitempty"`
	CSs      CSs      `json:"CSs,omitempty"`
	Computes Computes `json:"Computes,omitempty"`
	RGs      RGs      `json:"RGs,omitempty"`
	VMs      VMs      `json:"VMs,omitempty"`
}

type Accounts struct {
	Disabled uint64 `json:"DISABLED,omitempty"`
	Enabled  uint64 `json:"ENABLED,omitempty"`
}

type CSs struct {
	Disabled uint64 `json:"DISABLED,omitempty"`
	Enabled  uint64 `json:"ENABLED,omitempty"`
}

type Computes struct {
	Started uint64 `json:"Started,omitempty"`
	Stopped uint64 `json:"Stopped,omitempty"`
}

type RGs struct {
	Disabled uint64 `json:"DISABLED,omitempty"`
	Enabled  uint64 `json:"ENABLED,omitempty"`
}

type VMs struct {
	Halted  uint64 `json:"Halted,omitempty"`
	Running uint64 `json:"Running,omitempty"`
}

type APIsEndpoints struct {
	CloudAPI    CloudAPIEndpoints    `json:"cloudapi,omitempty"`
	CloudBroker CloudBrokerEndpoints `json:"cloudbroker,omitempty"`
	LibCloud    LibCloudEndpoints    `json:"libcloud,omitempty"`
	System      SystemEndpoints      `json:"system,omitempty"`
}

type CloudAPIEndpoints struct {
	All bool `json:"ALL,omitempty"`
}

type CloudBrokerEndpoints struct {
	All bool `json:"ALL,omitempty"`
}

type LibCloudEndpoints struct {
	All bool `json:"ALL,omitempty"`
}

type SystemEndpoints struct {
	All bool `json:"ALL,omitempty"`
}

type ResourceConsumption struct {
	// Consumed
	Consumed Resources `json:"Consumed"`

	// Reserved
	Reserved Resources `json:"Reserved"`

	// Username
	Username string `json:"username"`
}

type Resources struct {
	// CPU
	CPU uint64 `json:"cpu"`

	// Disksize
	DiskSize uint64 `json:"disksize"`

	// DiskSizeMax
	DiskSizeMax uint64 `json:"disksizemax"`

	// ExtIPs
	ExtIPs uint64 `json:"extips"`

	// GPU
	GPU uint64 `json:"gpu"`

	// RAM
	RAM uint64 `json:"ram"`

	// SEPs
	SEPs map[string]map[string]DiskUsage `json:"seps"`
}

// Disk usage
type DiskUsage struct {
	// Disk size
	DiskSize float64 `json:"disksize"`

	// Disk size max
	DiskSizeMax float64 `json:"disksizemax"`
}

type FoundElements []interface{}
