package member

const (
	Digimon Platform = 1 + iota
	Google
	Line
	Apple
)

const (
	PlatformNone Platform = -1
)

const (
	DigimonString = "credentials"
	GoogleString  = "google"
	LineString    = "line"
	AppleString   = "apple"
)

type Platform int8

func (p Platform) ToInt64() int64 {
	return int64(p)
}

// ToString - 將 Platform 轉為文字
func (p Platform) ToString() string {
	if result, ok := platformToString[p]; ok {
		return result
	}

	return ""
}

var platformToString = map[Platform]string{
	Digimon: DigimonString,
	Google:  GoogleString,
	Line:    LineString,
	Apple:   AppleString,
}

var stringToPlatform = map[string]Platform{
	DigimonString: Digimon,
	GoogleString:  Google,
	LineString:    Line,
	AppleString:   Apple,
}

// GetPlatformByPlatformCode - 從文字轉為 Platform
func GetPlatformByPlatformCode(code string) Platform {
	if result, ok := stringToPlatform[code]; ok {
		return result
	}

	return PlatformNone
}

// IsValid returns true if the platform is valid
func (p Platform) IsValid() bool {
	return p >= Digimon && p <= Apple
}
