package model

import (
	"errors"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/converter"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/sdktime"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/utils"
	"strings"
)

// ScalingGroupInstance 伸缩组实例详情
type ScalingGroupInstance struct {

	// 实例ID。
	InstanceId *string `json:"instance_id,omitempty"`

	// 实例名称。
	InstanceName *string `json:"instance_name,omitempty"`

	// 实例所在伸缩组ID。
	ScalingGroupId *string `json:"scaling_group_id,omitempty"`

	// 实例所在伸缩组名称。
	ScalingGroupName *string `json:"scaling_group_name,omitempty"`

	// 实例在伸缩组中的生命周期状态：  - INSERVICE：已启用 - PENDING：正在加入伸缩组 - PENDING_WAIT：等待（正在加入伸缩组） - REMOVING：正在移出伸缩组 - REMOVING_WAIT：等待（正在移出伸缩组） - STANDBY：已备用 - ENTERING_STANDBY：进入备用状态
	LifeCycleState *ScalingGroupInstanceLifeCycleState `json:"life_cycle_state,omitempty"`

	// 实例健康状态:INITAILIZING:初始化；NORMAL：正常；ERROR：错误。
	HealthStatus *ScalingGroupInstanceHealthStatus `json:"health_status,omitempty"`

	// 伸缩配置名称。如果返回为空，表示伸缩配置已经被删除。如果返回MANNUAL_ADD，表示实例为手动加入。
	ScalingConfigurationName *string `json:"scaling_configuration_name,omitempty"`

	// 伸缩配置ID。
	ScalingConfigurationId *string `json:"scaling_configuration_id,omitempty"`

	// 实例加入伸缩组的时间，遵循UTC时间。
	CreateTime *sdktime.SdkTime `json:"create_time,omitempty"`

	// 实例的实例保护属性。
	ProtectFromScalingDown *bool `json:"protect_from_scaling_down,omitempty"`
}

func (o ScalingGroupInstance) String() string {
	data, err := utils.Marshal(o)
	if err != nil {
		return "ScalingGroupInstance struct{}"
	}

	return strings.Join([]string{"ScalingGroupInstance", string(data)}, " ")
}

type ScalingGroupInstanceLifeCycleState struct {
	value string
}

type ScalingGroupInstanceLifeCycleStateEnum struct {
	INSERVICE     ScalingGroupInstanceLifeCycleState
	PENDING       ScalingGroupInstanceLifeCycleState
	REMOVING      ScalingGroupInstanceLifeCycleState
	PENDING_WAIT  ScalingGroupInstanceLifeCycleState
	REMOVING_WAIT ScalingGroupInstanceLifeCycleState
}

func GetScalingGroupInstanceLifeCycleStateEnum() ScalingGroupInstanceLifeCycleStateEnum {
	return ScalingGroupInstanceLifeCycleStateEnum{
		INSERVICE: ScalingGroupInstanceLifeCycleState{
			value: "INSERVICE",
		},
		PENDING: ScalingGroupInstanceLifeCycleState{
			value: "PENDING",
		},
		REMOVING: ScalingGroupInstanceLifeCycleState{
			value: "REMOVING",
		},
		PENDING_WAIT: ScalingGroupInstanceLifeCycleState{
			value: "PENDING_WAIT",
		},
		REMOVING_WAIT: ScalingGroupInstanceLifeCycleState{
			value: "REMOVING_WAIT",
		},
	}
}

func (c ScalingGroupInstanceLifeCycleState) Value() string {
	return c.value
}

func (c ScalingGroupInstanceLifeCycleState) MarshalJSON() ([]byte, error) {
	return utils.Marshal(c.value)
}

func (c *ScalingGroupInstanceLifeCycleState) UnmarshalJSON(b []byte) error {
	myConverter := converter.StringConverterFactory("string")
	if myConverter == nil {
		return errors.New("unsupported StringConverter type: string")
	}

	interf, err := myConverter.CovertStringToInterface(strings.Trim(string(b[:]), "\""))
	if err != nil {
		return err
	}

	if val, ok := interf.(string); ok {
		c.value = val
		return nil
	} else {
		return errors.New("convert enum data to string error")
	}
}

type ScalingGroupInstanceHealthStatus struct {
	value string
}

type ScalingGroupInstanceHealthStatusEnum struct {
	NORMAL       ScalingGroupInstanceHealthStatus
	ERROR        ScalingGroupInstanceHealthStatus
	INITAILIZING ScalingGroupInstanceHealthStatus
}

func GetScalingGroupInstanceHealthStatusEnum() ScalingGroupInstanceHealthStatusEnum {
	return ScalingGroupInstanceHealthStatusEnum{
		NORMAL: ScalingGroupInstanceHealthStatus{
			value: "NORMAL",
		},
		ERROR: ScalingGroupInstanceHealthStatus{
			value: "ERROR",
		},
		INITAILIZING: ScalingGroupInstanceHealthStatus{
			value: "INITAILIZING",
		},
	}
}

func (c ScalingGroupInstanceHealthStatus) Value() string {
	return c.value
}

func (c ScalingGroupInstanceHealthStatus) MarshalJSON() ([]byte, error) {
	return utils.Marshal(c.value)
}

func (c *ScalingGroupInstanceHealthStatus) UnmarshalJSON(b []byte) error {
	myConverter := converter.StringConverterFactory("string")
	if myConverter == nil {
		return errors.New("unsupported StringConverter type: string")
	}

	interf, err := myConverter.CovertStringToInterface(strings.Trim(string(b[:]), "\""))
	if err != nil {
		return err
	}

	if val, ok := interf.(string); ok {
		c.value = val
		return nil
	} else {
		return errors.New("convert enum data to string error")
	}
}
