/**
 * 單例基類(要先new在使用)
 * @example
 * export default class Test extends BaseSingleton<Test>() { ...... }
 * new Test();
 * Test.Instance.Init();
 */
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default function BaseSingleton<T>() {
	class BaseSingleton {
		public constructor() {
			if ((this as any)._instance == null) {
				BaseSingleton._instance = this as any;
			}
		}
		private static _instance: BaseSingleton = null;
		public static get Instance(): T {
			return (this as any)._instance;
		}

		/** 銷毀 */
		public Destroy(): void {
			(this as any)._instance = null;
		}
	}
	return BaseSingleton;
}