import { Ref, UnwrapNestedRefs, ComputedRef } from 'vue'

// type Method = (...args: unknown[]) => unknown

/**
 * 选取 Ref 类型的属性，Reactive 类型无法被选取
 */
export type StoreState<T> = UnwrapNestedRefs<{ [K in keyof T as T[K] extends ComputedRef ? never : T[K] extends Ref ? K : never]: T[K] }>

/**
 * 选取 Ref、ComputedRef 类型的属性，Reactive 类型无法被选取
 */
export type StoreToRefs<T> = { [K in keyof T as T[K] extends Ref ? K : never]: T[K] }

/**
 * 选取除 Function 类型外的所有属性，并转为 Ref 类型
 */
//export type StoreToRefs<T> = { [K in keyof T as T[K] extends Ref ? K : T[K] extends Method ? never : K]: T[K] extends ComputedRef ? T[K] : ToRef<T[K]> }

interface StoreProps<T extends object> {
    $id: string;
    $toRefs(): StoreToRefs<T>;
    $setState(callback: (state: StoreState<T>) => void): void;
    $reset(): void;
    $dispose(): void;
}

/**
 * 存储对象
 */
export type Store<T extends object> = UnwrapNestedRefs<T & StoreProps<T>>