/*
Copyright 2019 The Cloud-Barista Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package model is to handle object of CB-Tumblebug
package model

import (
	"time"
)

type CustomImageStatus string

const (
	MyImageAvailable   CustomImageStatus = "Available"
	MyImageUnavailable CustomImageStatus = "Unavailable"
)

// VmSnapshotReq is a struct to handle 'Create VM snapshot' request toward CB-Tumblebug.
type VmSnapshotReq struct {
	Name string `json:"name" example:"aws-ap-southeast-1-snapshot"`
}

type SpiderMyImageReq struct {
	ConnectionName string
	ReqInfo        struct {
		Name     string
		SourceVM string
	}
}

type SpiderMyImageInfo struct {
	IId IID // {NameId, SystemId}

	SourceVM IID

	Status CustomImageStatus // Available | Deleting

	CreatedTime  time.Time
	KeyValueList []KeyValue
}

type SpiderMyImageRegisterReq struct {
	ConnectionName string
	ReqInfo        struct {
		Name  string
		CSPId string // or, CSPid ?
	}
}

// CustomImageReq is a struct to handle a request for Create custom image (VM snapshot)
type CustomImageReq struct {
	// This field is for 'Register existing custom image'
	CspResourceId string `json:"cspResourceId"`

	ConnectionName string `json:"connectionName"`
	Name           string `json:"name" validate:"required"`
	SourceVmId     string `json:"sourceVmId"`
	Description    string `json:"description"`
}

// CustomImageInfo is a struct for custom image (VM snapshot)
type CustomImageInfo struct {
	// ResourceType is the type of the resource
	ResourceType string `json:"resourceType"`

	// Id is unique identifier for the object
	Id string `json:"id" example:"aws-ap-southeast-1"`
	// Uid is universally unique identifier for the object, used for labelSelector
	Uid string `json:"uid,omitempty" example:"wef12awefadf1221edcf"`
	// CspResourceName is name assigned to the CSP resource. This name is internally used to handle the resource.
	CspResourceName string `json:"cspResourceName,omitempty" example:"we12fawefadf1221edcf"`
	// CspResourceId is resource identifier managed by CSP
	CspResourceId string `json:"cspResourceId,omitempty" example:"csp-06eb41e14121c550a"`

	// Name is human-readable string to represent the object
	Name             string     `json:"name" example:"aws-ap-southeast-1"`
	Namespace        string     `json:"namespace,omitempty" example:"default"` // required to save in RDB
	ConnectionName   string     `json:"connectionName" example:"aws-ap-southeast-1"`
	ConnectionConfig ConnConfig `json:"connectionConfig" gorm:"type:text;serializer:json"`

	SourceVmId           string            `json:"sourceVmId" example:"aws-ap-southeast-1-1"`
	Description          string            `json:"description"`
	CreationDate         time.Time         `json:"creationDate,omitempty" example:"2022-10-18T08:12:48Z"`
	GuestOS              string            `json:"guestOS,omitempty"` // Windows7, Ubuntu etc.
	Status               CustomImageStatus `json:"status" example:"Available"`
	KeyValueList         []KeyValue        `json:"keyValueList" gorm:"type:text;serializer:json"`
	AssociatedObjectList []string          `json:"associatedObjectList,omitempty" gorm:"type:text;serializer:json"`
	IsAutoGenerated      bool              `json:"isAutoGenerated,omitempty"`

	// SystemLabel is for describing the Resource in a keyword (any string can be used) for special System purpose
	SystemLabel string `json:"systemLabel,omitempty" example:"Managed by CB-Tumblebug" default:""`
}
