// Copyright 2019 Yunion
//
// 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 apis

import "yunion.io/x/pkg/utils"

const (
	SERVICE_TYPE_IMAGE             = "image"
	SERVICE_TYPE_OFFLINE_CLOUDMETA = "offlinecloudmeta"
	SERVICE_TYPE_CLOUDID           = "cloudid"
	SERVICE_TYPE_CLOUDEVENT        = "cloudevent"
	SERVICE_TYPE_DEVTOOL           = "devtool"
	SERVICE_TYPE_ANSIBLE           = "ansible"
	SERVICE_TYPE_CLOUDMETA         = "cloudmeta"
	SERVICE_TYPE_YUNIONCONF        = "yunionconf"
	SERVICE_TYPE_METER             = "meter"
	SERVICE_TYPE_SCHEDULER         = "scheduler"
	SERVICE_TYPE_VNCPROXY          = "vncproxy"
	SERVICE_TYPE_KEYSTONE          = "identity"
	SERVICE_TYPE_NOTIFY            = "notify"
	SERVICE_TYPE_MONITOR           = "monitor"
	SERVICE_TYPE_LOG               = "log"
	SERVICE_TYPE_REGION            = "compute"
	SERVICE_TYPE_CLOUDMON          = "cloudmon"
	SERVICE_TYPE_VPCAGENT          = "vpcagent"

	SERVICE_TYPE_ETCD             = "etcd"
	SERVICE_TYPE_INFLUXDB         = "influxdb"
	SERVICE_TYPE_NTP              = "ntp"
	SERVICE_TYPE_VICTORIA_METRICS = "victoria-metrics"

	SERVICE_TYPE_SCHEDULEDTASK = "scheduledtask"

	SERVICE_TYPE_APIMAP = "apimap"

	SERVICE_TYPE_LLM = "llm"

	STATUS_UPDATE_TAGS        = "update_tags"
	STATUS_UPDATE_TAGS_FAILED = "update_tags_fail"

	STATUS_START_SYNC_STATUS = "start_sync_status"

	STATUS_SYNC_STATUS   = "sync_status"
	STATUS_DELETING      = "deleting"
	STATUS_DELETE_FAILED = "delete_failed"
	STATUS_CHANGE_CONFIG = "change_config"
	STATUS_UNKNOWN       = "unknown"
	STATUS_CREATING      = "creating"
	STATUS_AVAILABLE     = "available"
	STATUS_CREATE_FAILED = "create_failed"

	// 更改计费模式
	STATUS_CHANGE_BILLING_TYPE        = "change_billing_type"
	STATUS_CHANGE_BILLING_TYPE_FAILED = "change_billing_type_failed"

	CLOUD_TAG_PREFIX     = "ext:"
	USER_TAG_PREFIX      = "user:"
	SYS_CLOUD_TAG_PREFIX = "sys:"
	// Such tags have inherited and isolated properties
	CLASS_TAG_PREFIX = "cls:"

	ORGANIZATION_TAG_PREFIX = "org:"

	SKU_STATUS_AVAILABLE = "available"
	SKU_STATUS_SOLDOUT   = "soldout"

	MetaServiceMonitorAgentUrl = "http://%s/monitor"
)

var (
	NO_RESOURCE_SERVICES = []string{
		SERVICE_TYPE_OFFLINE_CLOUDMETA,
		SERVICE_TYPE_CLOUDMETA,
		SERVICE_TYPE_SCHEDULER,
		SERVICE_TYPE_VNCPROXY,
		SERVICE_TYPE_KEYSTONE,
		SERVICE_TYPE_ETCD,
		SERVICE_TYPE_INFLUXDB,
		SERVICE_TYPE_CLOUDMON,
		SERVICE_TYPE_METER,
		SERVICE_TYPE_CLOUDEVENT,
		SERVICE_TYPE_ANSIBLE,
		SERVICE_TYPE_INFLUXDB,
		SERVICE_TYPE_VICTORIA_METRICS,
		SERVICE_TYPE_APIMAP,
		SERVICE_TYPE_LOG,
		"autoupdate",
		"yunionagent",
		"webconsole",
		"esxiagent",
		"s3gateway",
		"common",
		"websocket",
		"echarts-ssr",
		"lbagent",
		"vpcagent",
		"cloudwatcher",
		"cloudnet",
		"repo",
		"cloudproxy",
		"apigateway",
		"yunionapi",
		"billing",
		SERVICE_TYPE_ETCD,
		"itsm",
		SERVICE_TYPE_NTP,
		"kafka",
	}

	EXTERNAL_SERVICES = []string{
		SERVICE_TYPE_OFFLINE_CLOUDMETA,
		SERVICE_TYPE_CLOUDMETA,
		SERVICE_TYPE_SCHEDULER,
		SERVICE_TYPE_VNCPROXY,
		SERVICE_TYPE_ETCD,
		SERVICE_TYPE_INFLUXDB,
		SERVICE_TYPE_INFLUXDB,
		SERVICE_TYPE_VICTORIA_METRICS,
		SERVICE_TYPE_LOG,
		"s3gateway",
		"common",
		"websocket",
		"echarts-ssr",
		"cloudwatcher",
		"cloudnet",
		"repo",
		SERVICE_TYPE_ETCD,
		"itsm",
		SERVICE_TYPE_NTP,
		"kafka",
	}
)

const (
	COMPRESS_FORMAT_GZIP   = "gzip"
	COMPRESS_FORMAT_TAR_GZ = "tar.gz"
)

const (
	OS_ARCH_ALL = "all"

	OS_ARCH_X86   = "x86"
	OS_ARCH_ARM   = "arm"
	OS_ARCH_RISCV = "riscv"

	OS_ARCH_I386    = "i386"
	OS_ARCH_X86_32  = "x86_32"
	OS_ARCH_X86_64  = "x86_64"
	OS_ARCH_AARCH32 = "aarch32"
	OS_ARCH_AARCH64 = "aarch64"
	OS_ARCH_RISCV32 = "riscv32"
	OS_ARCH_RISCV64 = "riscv64"
)

var (
	ARCH_X86 = []string{
		OS_ARCH_X86,
		OS_ARCH_I386,
		OS_ARCH_X86_32,
		OS_ARCH_X86_64,
	}
	ARCH_ARM = []string{
		OS_ARCH_ARM,
		OS_ARCH_AARCH32,
		OS_ARCH_AARCH64,
	}
	ARCH_RISCV = []string{
		OS_ARCH_RISCV,
		OS_ARCH_RISCV32,
		OS_ARCH_RISCV64,
	}
)

func IsARM(osArch string) bool {
	return utils.IsInStringArray(osArch, ARCH_ARM)
}

func IsX86(osArch string) bool {
	return utils.IsInStringArray(osArch, ARCH_X86)
}

func IsRISCV(osArch string) bool {
	return utils.IsInStringArray(osArch, ARCH_RISCV)
}

func IsIllegalSearchDomain(domain string) bool {
	switch domain {
	case "cloud.onecloud.io":
		return true
	}
	return false
}

func IsSameArch(arch1, arch2 string) bool {
	if arch1 == arch2 {
		return true
	}
	if IsARM(arch1) && IsARM(arch2) {
		return true
	}
	if IsX86(arch1) && IsX86(arch2) {
		return true
	}
	if IsRISCV(arch1) && IsRISCV(arch2) {
		return true
	}
	return false
}
