package id

import (
	"errors"
)

// 设计规则参看 kingame 的 README
var (
	ErrInvalidLogicId = errors.New("Invalid logic id")
)

type LogicId struct {
	funcId uint64 //999
	cataId uint64 //99
	subId  uint64 //99
	instId uint64 //99
}

func Parse(logicId uint64) (*LogicId, error) {
	sid := &LogicId{}
	sid.instId = logicId % 100
	sid.subId = logicId / 100 % 100
	sid.cataId = logicId / 10000 % 100

	sid.funcId = logicId / 1000000
	if sid.funcId >= 1000 || sid.funcId <= 0 {
		return nil, ErrInvalidLogicId
	}
	return sid, nil
}
