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"`
	Computes Computes `json:"Computes,omitempty"`
	RGs      RGs      `json:"RGs,omitempty"`
}

type Accounts struct {
	Destroying uint64 `json:"DESTROYING,omitempty"`
	Confirmed  uint64 `json:"CONFIRMED,omitempty"`
	Disabled   uint64 `json:"DISABLED,omitempty"`
	Deleted    uint64 `json:"DELETED,omitempty"`
}

type Computes struct {
	Starting      uint64 `json:"STARTING,omitempty"`
	Started       uint64 `json:"STARTED,omitempty"`
	Stopping      uint64 `json:"STOPPING,omitempty"`
	Stopped       uint64 `json:"STOPPED,omitempty"`
	Paused        uint64 `json:"PAUSED,omitempty"`
	Pausing       uint64 `json:"PAUSING,omitempty"`
	Merge         uint64 `json:"MERGE,omitempty"`
	Migrating     uint64 `json:"MIGRATING,omitempty"`
	MigratingIn   uint64 `json:"MIGRATING_IN,omitempty"`
	MigratingOut  uint64 `json:"MIGRATING_OUT,omitempty"`
	Down          uint64 `json:"DOWN,omitempty"`
	Scheduled     uint64 `json:"SCHEDULED,omitempty"`
	BackupStopped uint64 `json:"BACKUP_STOPPED,omitempty"`
	BackupRunning uint64 `json:"BACKUP_RUNNING,omitempty"`
	SnapСreate    uint64 `json:"SNAPCREATE,omitempty"`
	Cloning       uint64 `json:"CLONING,omitempty"`
	Rollback      uint64 `json:"ROLLBACK,omitempty"`
}

type RGs struct {
	Modeled    uint64 `json:"MODELED,omitempty"`
	Created    uint64 `json:"CREATED,omitempty"`
	Deleted    uint64 `json:"DELETED,omitempty"`
	Deleting   uint64 `json:"DELETING,omitempty"`
	Destroying uint64 `json:"DESTROYING,omitempty"`
	Disabled   uint64 `json:"DISABLED,omitempty"`
	Disabling  uint64 `json:"DISABLING,omitempty"`
	Enabling   uint64 `json:"ENABLING,omitempty"`
	Restoring  uint64 `json:"RESTORING,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{}
