export type PermissionStatus = 'granted' | 'denied' | 'prompt' | 'unsupported';
export type StorageStatus = 'persisted' | 'available' | 'unsupported';

type RawPermissionState = PermissionState | 'default' | null | undefined;

export function normalizePermissionState(state: RawPermissionState): PermissionStatus {
  if (!state) {
    return 'unsupported';
  }

  if (state === 'default') {
    return 'prompt';
  }

  return state;
}

export function resolveStorageStatus(persisted: boolean | null, supported: boolean): StorageStatus {
  if (!supported) {
    return 'unsupported';
  }

  if (persisted) {
    return 'persisted';
  }

  return 'available';
}
