package code

type Scope uint32    // SS (00..99)
type Category uint32 // CCC (000..999)
type Detail uint32   // DDD (000..999)

const (
	Unset                     Scope  = 0
	MaxScope                  Scope  = 99
	CategoryMultiplier               = 1000
	ScopeMultiplier                  = 1000000
	NonCode                   uint32 = 0
	OK                        uint32 = 0
	DefaultSuccessFullCode           = "102000"
	DefaultSuccessMessage            = "SUCCESS"
	DefaultSuccessFullCodeInt        = 102000
)

const (
	MaxCategory Category = 999
	MaxDetail   Detail   = 999

	DefaultCategory Category = 0
	DefaultDetail   Detail   = 0
)

// Valid reports whether s is within the allowed scope range.
func (s Scope) Valid() bool {
	return s <= MaxScope
}

// Valid reports whether c is within the allowed category range.
func (c Category) Valid() bool {
	return c <= MaxCategory
}

// Valid reports whether d is within the allowed detail range.
func (d Detail) Valid() bool {
	return d <= MaxDetail
}

// Input errors (101-106)
const (
	InputInvalidFormat          Category = 101
	InputNotValidImplementation Category = 102
	InputInvalidRange           Category = 103
	InputMissingRequired        Category = 104
	InputUnsupportedMedia       Category = 105
	InputPayloadTooLarge        Category = 106
)

// DB errors (201-204)
const (
	DBError       Category = 201
	DBDataConvert Category = 202
	DBDuplicate   Category = 203
	DBUnavailable Category = 204
)

// Resource errors (301-311)
const (
	ResNotFound           Category = 301
	ResInvalidFormat      Category = 302
	ResAlreadyExist       Category = 303
	ResInsufficient       Category = 304
	ResInsufficientPerm   Category = 305
	ResInvalidMeasureID   Category = 306
	ResExpired            Category = 307
	ResMigrated           Category = 308
	ResInvalidState       Category = 309
	ResInsufficientQuota  Category = 310
	ResMultiOwner         Category = 311
	ResPreconditionFailed Category = 312
	ResLocked             Category = 313
)

// GRPC mapping category (400)
const (
	CatGRPC Category = 400
)

// Auth errors (501-505)
const (
	AuthUnauthorized       Category = 501
	AuthExpired            Category = 502
	AuthInvalidPosixTime   Category = 503
	AuthSigPayloadMismatch Category = 504
	AuthForbidden          Category = 505
	AuthMethodNotAllowed   Category = 506
)

// System errors (601-604)
const (
	SysInternal       Category = 601
	SysMaintain       Category = 602
	SysTimeout        Category = 603
	SysTooManyRequest Category = 604
	SysNotImplemented Category = 605
	SysClientTimeout  Category = 606
)

// PubSub errors (701-703)
const (
	PSuPublish  Category = 701
	PSuConsume  Category = 702
	PSuTooLarge Category = 703
)

// Service errors (801-804)
const (
	SvcInternal    Category = 801
	SvcThirdParty  Category = 802
	SvcHTTP400     Category = 803
	SvcMaintenance Category = 804
	SvcRateLimited Category = 805
)

// Service/module scopes (SS).
const (
	Facade                    Scope = 10
	LocalAPI                  Scope = 11
	GearAuditLog              Scope = 12
	GearConsistMGR            Scope = 13
	GearDataReport            Scope = 14
	GearEventReactor          Scope = 15
	GearImporterScope         Scope = 16
	MonitorDataProcessorScope Scope = 17
	OrbitDistributedScheduler Scope = 18
	OrbitEventMGR             Scope = 19
	OrbitIgniter              Scope = 20
	OrbitLauncher             Scope = 21
	OrbitMonitor              Scope = 22
	OrbitPowerMGR             Scope = 23
	OrbitTasker               Scope = 24
	PluginVcenterHSM          Scope = 25
	PluginMGR                 Scope = 26
	GearAssetMgr              Scope = 27

	// Gateway domain module scopes (logic + usecase).
	Auth         Scope = 28
	Member       Scope = 29
	Notification Scope = 30
	Permission   Scope = 31
)
