import { PermissionUserContext } from './permission-context.types';
import { DataScopeMode } from './permission-resolver.helpers';

export function getPermissionContext(
  user?: Partial<PermissionUserContext> & { sub?: string; owner_id?: string; role?: string },
): PermissionUserContext {
  return {
    sub: user?.sub ?? '',
    owner_id: user?.owner_id ?? user?.sub ?? '',
    role: user?.role ?? 'member',
    access_role_id: user?.access_role_id ?? null,
  };
}

export function parseDataScope(value?: string): DataScopeMode | undefined {
  if (value === 'own' || value === 'all') {
    return value;
  }

  return undefined;
}
