import { Membership } from '@dvn/core/models/membership';
import { MembershipConfig } from '@dvn/core/models/membership-config';
import { User } from '@dvn/kimlik/api/models';
import { UserSettings } from '@dvn/kimlik/api/models/UserSettings';
import { CookieStorage } from '@dvn/kimlik/storage/cookie';
import { getRouteParams } from './route';
export function getSessionDetails(groupId) {
  const { domain } = getRouteParams(location.pathname);
  const jwt = new CookieStorage().get('mt_at');
  const sessionToken = new CookieStorage().get('mt_st');
  const context = {
    organisationDomain: domain,
    organisationId: new CookieStorage().get('mt_oid'),
    userId: new CookieStorage().get('mt_uid'),
    role: new CookieStorage().get('mt_role'),
  };
  const headers = {
    Client: 'd2ViLWNsaWVu',
  };
  if (jwt) {
    headers['Authorization'] = `Bearer ${jwt}`;
    headers['Session-Token'] = sessionToken;
  }
  else {
    headers['Session-Token'] = `NTdiMzY3NjBlNjNiY2UxZWViMDAwMDA0`;
  }
  context.groupId = groupId;
  return { context, headers };
}
export function getUserSettings(timeFormat, timeZone, language, isZoomAuthenticated) {
  const authPlatforms = [];
  if (isZoomAuthenticated) {
    authPlatforms.push({
      id: 'zoom',
      name: 'Zoom',
      scope: []
    });
  }
  return UserSettings.decode({ timeFormat, timeZone, language, authPlatforms });
}
export function generateMembershipForRole(role) {
  return Membership.decode({
    config: generateMembershipConfigForRole(role),
  });
}
export function generateMembershipConfigForRole(role) {
  return MembershipConfig.decode({
    _id: role === 'mentor' ? 'mentors' : 'mentees',
    roleName: role
  });
}
export function getUser(id) {
  return User.decode({ _id: id });
}
