package models

import (
	"encoding/json"
	"time"
)

type CloudEventReceived struct {
	CloudEvent struct {
		ID          string `json:"id"`
		Specversion string `json:"specversion"`
		Source      string `json:"source"`
		Type        string `json:"type"`
		Time        string `json:"time"` // Modified from time.Time
		Data        struct {
			ChainID         int    `json:"ChainId"`
			ChangeTag       string `json:"ChangeTag"`
			ComputeResource struct {
				ComputeResource struct {
					Type  string `json:"Type"`
					Value string `json:"Value"`
				} `json:"ComputeResource"`
				Name string `json:"Name"`
			} `json:"ComputeResource"`
			CreatedTime string `json:"CreatedTime"` // Modified from time.Time
			Datacenter  struct {
				Datacenter struct {
					Type  string `json:"Type"`
					Value string `json:"Value"`
				} `json:"Datacenter"`
				Name string `json:"Name"`
			} `json:"Datacenter"`
			Ds                   interface{} `json:"Ds"`
			Dvs                  interface{} `json:"Dvs"`
			FullFormattedMessage string      `json:"FullFormattedMessage"`
			Host                 struct {
				Host struct {
					Type  string `json:"Type"`
					Value string `json:"Value"`
				} `json:"Host"`
				Name string `json:"Name"`
			} `json:"Host"`
			Key         int         `json:"Key"`
			Net         interface{} `json:"Net"`
			SrcTemplate struct {
				Name string `json:"Name"`
				VM   struct {
					Type  string `json:"Type"`
					Value string `json:"Value"`
				} `json:"Vm"`
			} `json:"SrcTemplate"`
			Template bool   `json:"Template"`
			UserName string `json:"UserName"`
			VM       struct {
				Name string `json:"Name"`
				VM   struct {
					Type  string `json:"Type"`
					Value string `json:"Value"`
				} `json:"Vm"`
			} `json:"Vm"`
			ConfigSpec    *json.RawMessage       `json:"configSpec"`
			ConfigChanges *ConfigChangesReceived `json:"configChanges"` // Modified to separate struct
		} `json:"data"`
	} `json:"cloudEvent"`
}

type ImportReceived struct {
	Name            string  `json:"Name"`
	Vcenter         string  `json:"Vcenter"`
	VmId            string  `json:"VmId"`
	InitialRam      int     `json:"InitialRam"`
	PowerState      int     `json:"PowerState"`
	CreationTime    int     `json:"CreationTime"`
	InitialVcpus    int     `json:"InitialVcpus"`
	ProvisionedDisk float64 `json:"ProvisionedDisk"`
	Folder          string  `json:"Folder"`
	ResourcePool    string  `json:"ResourcePool"`
	Datacenter      string  `json:"Datacenter"`
	Cluster         string  `json:"Cluster"`
}

type ConfigChangesReceived struct {
	Modified string `json:"modified"`
}

// This probably needs more fields added so not in use yet
type ConfigSpec struct {
	AlternateGuestName    string    `json:"AlternateGuestName"`
	Annotation            string    `json:"Annotation"`
	BootOptions           any       `json:"BootOptions"`
	ChangeTrackingEnabled any       `json:"ChangeTrackingEnabled"`
	ChangeVersion         string    `json:"ChangeVersion"`
	ConsolePreferences    any       `json:"ConsolePreferences"`
	CPUAffinity           any       `json:"CpuAffinity"`
	CPUAllocation         any       `json:"CpuAllocation"`
	CPUFeatureMask        any       `json:"CpuFeatureMask"`
	CPUHotAddEnabled      any       `json:"CpuHotAddEnabled"`
	CPUHotRemoveEnabled   any       `json:"CpuHotRemoveEnabled"`
	CreateDate            time.Time `json:"CreateDate"`
	Crypto                any       `json:"Crypto"`
	DeviceChange          []struct {
		Backing any `json:"Backing"`
		Device  struct {
			Backing         *BackingSpec `json:"Backing,omitempty"`
			CapacityInBytes int          `json:"CapacityInBytes"`
			CapacityInKB    int          `json:"CapacityInKB"`
			Connectable     struct {
				AllowGuestControl bool   `json:"AllowGuestControl"`
				Connected         bool   `json:"Connected"`
				MigrateConnect    string `json:"MigrateConnect"`
				StartConnected    bool   `json:"StartConnected"`
				Status            string `json:"Status"`
			} `json:"Connectable"`
			ControllerKey int `json:"ControllerKey"`
			DeviceInfo    struct {
				Label   string `json:"Label"`
				Summary string `json:"Summary"`
			} `json:"DeviceInfo"`
			ExternalID         string `json:"ExternalId"`
			MacAddress         string `json:"MacAddress"`
			ResourceAllocation struct {
				Limit       int `json:"Limit"`
				Reservation int `json:"Reservation"`
				Share       struct {
					Level  string `json:"Level"`
					Shares int    `json:"Shares"`
				} `json:"Share"`
			} `json:"ResourceAllocation"`
			SlotInfo                   any    `json:"SlotInfo"`
			UnitNumber                 int    `json:"UnitNumber"`
			UptCompatibilityEnabled    bool   `json:"UptCompatibilityEnabled"`
			WakeOnLanEnabled           bool   `json:"WakeOnLanEnabled"`
			DiskObjectID               string `json:"DiskObjectId"`
			Iofilter                   any    `json:"Iofilter"`
			Key                        int    `json:"Key"`
			NativeUnmanagedLinkedClone any    `json:"NativeUnmanagedLinkedClone"`
			Shares                     any    `json:"Shares"`
			StorageIOAllocation        struct {
				Limit       int `json:"Limit"`
				Reservation any `json:"Reservation"`
				Shares      struct {
					Level  string `json:"Level"`
					Shares int    `json:"Shares"`
				} `json:"Shares"`
			} `json:"StorageIOAllocation"`
			VDiskID               any `json:"VDiskId"`
			VFlashCacheConfigInfo any `json:"VFlashCacheConfigInfo"`
		} `json:"Device,omitempty"`
		FileOperation string `json:"FileOperation"`
		Operation     string `json:"Operation"`
		Profile       []struct {
			ProfileData struct {
				ExtensionKey string    `json:"ExtensionKey"`
				ObjectData   time.Time `json:"ObjectData"`
			} `json:"ProfileData"`
			ProfileID       string `json:"ProfileId"`
			ProfileParams   any    `json:"ProfileParams"`
			ReplicationSpec any    `json:"ReplicationSpec"`
		} `json:"Profile"`
	} `json:"DeviceChange"`
	ExtraConfig any `json:"ExtraConfig"`
	Files       struct {
		FtMetadataDirectory string `json:"FtMetadataDirectory"`
		LogDirectory        string `json:"LogDirectory"`
		SnapshotDirectory   string `json:"SnapshotDirectory"`
		SuspendDirectory    string `json:"SuspendDirectory"`
		VMPathName          string `json:"VmPathName"`
	} `json:"Files"`
	Firmware                     string `json:"Firmware"`
	Flags                        any    `json:"Flags"`
	FtInfo                       any    `json:"FtInfo"`
	GuestAutoLockEnabled         any    `json:"GuestAutoLockEnabled"`
	GuestID                      string `json:"GuestId"`
	GuestMonitoringModeInfo      any    `json:"GuestMonitoringModeInfo"`
	InstanceUUID                 string `json:"InstanceUuid"`
	LatencySensitivity           any    `json:"LatencySensitivity"`
	LocationID                   string `json:"LocationId"`
	ManagedBy                    any    `json:"ManagedBy"`
	MaxMksConnections            int    `json:"MaxMksConnections"`
	MemoryAffinity               any    `json:"MemoryAffinity"`
	MemoryAllocation             any    `json:"MemoryAllocation"`
	MemoryHotAddEnabled          any    `json:"MemoryHotAddEnabled"`
	MemoryMB                     int    `json:"MemoryMB"`
	MemoryReservationLockedToMax any    `json:"MemoryReservationLockedToMax"`
	MessageBusTunnelEnabled      any    `json:"MessageBusTunnelEnabled"`
	MigrateEncryption            string `json:"MigrateEncryption"`
	Name                         string `json:"Name"`
	NestedHVEnabled              any    `json:"NestedHVEnabled"`
	NetworkShaper                any    `json:"NetworkShaper"`
	NpivDesiredNodeWwns          int    `json:"NpivDesiredNodeWwns"`
	NpivDesiredPortWwns          int    `json:"NpivDesiredPortWwns"`
	NpivNodeWorldWideName        any    `json:"NpivNodeWorldWideName"`
	NpivOnNonRdmDisks            any    `json:"NpivOnNonRdmDisks"`
	NpivPortWorldWideName        any    `json:"NpivPortWorldWideName"`
	NpivTemporaryDisabled        any    `json:"NpivTemporaryDisabled"`
	NpivWorldWideNameOp          string `json:"NpivWorldWideNameOp"`
	NpivWorldWideNameType        string `json:"NpivWorldWideNameType"`
	NumCPUs                      int    `json:"NumCPUs"`
	NumCoresPerSocket            int    `json:"NumCoresPerSocket"`
	PowerOpInfo                  any    `json:"PowerOpInfo"`
	RepConfig                    any    `json:"RepConfig"`
	ScheduledHardwareUpgradeInfo any    `json:"ScheduledHardwareUpgradeInfo"`
	SevEnabled                   any    `json:"SevEnabled"`
	SgxInfo                      any    `json:"SgxInfo"`
	SwapPlacement                string `json:"SwapPlacement"`
	Tools                        any    `json:"Tools"`
	UUID                         string `json:"Uuid"`
	VAppConfig                   any    `json:"VAppConfig"`
	VAppConfigRemoved            any    `json:"VAppConfigRemoved"`
	VAssertsEnabled              any    `json:"VAssertsEnabled"`
	VPMCEnabled                  any    `json:"VPMCEnabled"`
	VcpuConfig                   any    `json:"VcpuConfig"`
	Version                      string `json:"Version"`
	VirtualICH7MPresent          any    `json:"VirtualICH7MPresent"`
	VirtualSMCPresent            any    `json:"VirtualSMCPresent"`
	VMProfile                    any    `json:"VmProfile"`
}

type BackingSpec struct {
	Port struct {
		ConnectionCookie int    `json:"ConnectionCookie"`
		PortKey          string `json:"PortKey"`
		PortgroupKey     string `json:"PortgroupKey"`
		SwitchUUID       string `json:"SwitchUuid"`
	} `json:"Port"`
	BackingObjectID string `json:"BackingObjectId"`
	ChangeID        string `json:"ChangeId"`
	ContentID       string `json:"ContentId"`
	Datastore       struct {
		Type  string `json:"Type"`
		Value string `json:"Value"`
	} `json:"Datastore"`
	DeltaDiskFormat        string `json:"DeltaDiskFormat"`
	DeltaDiskFormatVariant string `json:"DeltaDiskFormatVariant"`
	DeltaGrainSize         int    `json:"DeltaGrainSize"`
	DigestEnabled          any    `json:"DigestEnabled"`
	DiskMode               string `json:"DiskMode"`
	EagerlyScrub           bool   `json:"EagerlyScrub"`
	FileName               string `json:"FileName"`
	KeyID                  any    `json:"KeyId"`
	Parent                 any    `json:"Parent"`
	Sharing                string `json:"Sharing"`
	Split                  any    `json:"Split"`
	ThinProvisioned        bool   `json:"ThinProvisioned"`
	UUID                   string `json:"Uuid"`
	WriteThrough           any    `json:"WriteThrough"`
}
