import type { StoreStatus } from '../types';

export type PermissionStatus = StoreStatus;

export interface PermissionState {
  /** 已校验通过的权限码 */
  permissions: string[];
  status: PermissionStatus;
}

export interface PermissionActions {
  /** 开始后台校验：非 ready 状态时清空权限并进入 loading（fail-closed） */
  beginPermissionVerification: () => void;
  /** 写入已校验的权限 */
  writePermissions: (permissions: string[]) => void;
  /** 清空权限（退出登录 / 401） */
  clearPermissions: (status?: PermissionStatus) => void;
}

export type PermissionStore = PermissionState & PermissionActions;

/** 持久化子集：只保存权限码，状态恢复后一律为 unknown */
export interface PermissionPersistedState {
  permissions: string[];
}
