package errors

type ErrorCode int32

const SUCCESS = 0

const (
	PanicError        ErrorCode = -1
	UnrecognizedError ErrorCode = -2
	K8SClientError    ErrorCode = -3
	AWSClientError    ErrorCode = -4

	IOError           ErrorCode = 1001
	B64DecodeError    ErrorCode = 1002
	ParameterInvalid  ErrorCode = 1003
	MarshalError      ErrorCode = 1004
	UnmarshalError    ErrorCode = 1005
	UnsupportedRegion ErrorCode = 1006
	EmptyEnvError     ErrorCode = 1007
	ConvertError      ErrorCode = 1008
	ParamParseError   ErrorCode = 1009
	AbsenceOfConfig   ErrorCode = 1010
	ConfigInvalid     ErrorCode = 1012
	GormDBError       ErrorCode = 1013
	GrpcServiceError  ErrorCode = 1014
	OSError           ErrorCode = 1015
	S3Error           ErrorCode = 1016

	SendMessureError ErrorCode = 2001
)

type ErrorCodeExplanation struct {
	explanation string
	httpCode    int
}

func (t ErrorCode) GetHttpCode() int {
	return explanationContainer[t].httpCode
}

func (t ErrorCode) Equal(code int32) bool {
	return code == int32(t)
}

func (t ErrorCode) Explain() string {
	return explanationContainer[t].explanation
}

var explanationContainer = map[ErrorCode]ErrorCodeExplanation{
	PanicError:        {"panic", 500},
	UnrecognizedError: {"unrecognized error", 500},
	K8SClientError:    {"k8s client error", 500},
	AWSClientError:    {"aws client error", 500},

	ParameterInvalid:  {"parameter is invalid", 400},
	MarshalError:      {"marshal error", 500},
	UnmarshalError:    {"unmarshal error", 500},
	UnsupportedRegion: {"vendor or region is not supported", 400},
	IOError:           {"io read file error", 500},
	B64DecodeError:    {"base64 decode error", 500},
	EmptyEnvError:     {"empty env error", 400},
	ConvertError:      {"convert error", 400},
	ParamParseError:   {"parameter parse error", 400},
	AbsenceOfConfig:   {"absence of config", 500},
	ConfigInvalid:     {"config is invalid", 500},
	GormDBError:       {"operate database by gorm failed", 500},
	GrpcServiceError:  {"call grpc service failed", 500},
	OSError:           {"os operate failed", 500},
	S3Error:           {"S3 failed", 500},
	SendMessureError:  {"send messure data failed", 500},
}
