import { A as APIBase } from './kimlikApi-7350588e.js';
import { g as generateFieldModelFromRawData } from './FieldModelGenerator-1ee7fda2.js';

// tslint:disable:variable-name
var Role;
(function (Role) {
  Role["Admin"] = "admin";
  Role["Mentee"] = "mentee";
  Role["Mentor"] = "mentor";
})(Role || (Role = {}));
var Collection;
(function (Collection) {
  Collection["Activities"] = "activities";
  Collection["Announcements"] = "announcements";
  Collection["Availabilities"] = "availabilities";
  Collection["Configs"] = "configs";
  Collection["Conversations"] = "conversations";
  Collection["Events"] = "events";
  Collection["Feedbacks"] = "feedbacks";
  Collection["Forms"] = "forms";
  Collection["FormResponses"] = "formResponses";
  Collection["Groups"] = "groups";
  Collection["Invitations"] = "invitations";
  Collection["MeetingGoalConfigs"] = "meetingGoalConfigs";
  Collection["Mentorships"] = "mentorships";
  Collection["Messages"] = "messages";
  Collection["Metadatas"] = "metadatas";
  Collection["Notes"] = "notes";
  Collection["Organisations"] = "organisations";
  Collection["Sessions"] = "sessions";
  Collection["Subscriptions"] = "subscriptions";
  Collection["Users"] = "users";
  Collection["WhiteLabels"] = "whiteLabels";
})(Collection || (Collection = {}));
class MentornityModel {
  Id() {
    return this._id;
  }
}
class ModelReference extends MentornityModel {
  constructor(_id, _class) {
    super();
    this._id = _id;
    this._class = _class;
    this._type = 'reference';
  }
  static decode(json) {
    return Object.assign(Object.create(ModelReference.prototype), json);
  }
}
var ActivityVerb;
(function (ActivityVerb) {
  ActivityVerb["AddEventNote"] = "addEventNote";
  ActivityVerb["CancelAvailability"] = "cancelAvailability";
  ActivityVerb["CancelEvent"] = "cancelEvent";
  ActivityVerb["CreateAvailability"] = "createAvailability";
  ActivityVerb["CreateEvent"] = "createEvent";
  ActivityVerb["UpdateEvent"] = "updateEvent";
  ActivityVerb["SetEventNotOccurred"] = "setEventNotOccurred";
})(ActivityVerb || (ActivityVerb = {}));
var AnnouncementStatus;
(function (AnnouncementStatus) {
  AnnouncementStatus["Published"] = "published";
  AnnouncementStatus["Unpublished"] = "unpublished";
})(AnnouncementStatus || (AnnouncementStatus = {}));
var AnnouncementTarget;
(function (AnnouncementTarget) {
  AnnouncementTarget["All"] = "all";
  AnnouncementTarget["Mentee"] = "mentee";
  AnnouncementTarget["Mentor"] = "mentor";
})(AnnouncementTarget || (AnnouncementTarget = {}));
var ConfigMenteeType;
(function (ConfigMenteeType) {
  ConfigMenteeType["Individual"] = "individual";
  ConfigMenteeType["Group"] = "group";
  ConfigMenteeType["GroupedIndividual"] = "groupedIndividual";
})(ConfigMenteeType || (ConfigMenteeType = {}));
var ConfigMentorMenteeSubscription;
(function (ConfigMentorMenteeSubscription) {
  ConfigMentorMenteeSubscription["Implicit"] = "implicit";
  ConfigMentorMenteeSubscription["Restricted"] = "restricted";
})(ConfigMentorMenteeSubscription || (ConfigMentorMenteeSubscription = {}));
class Config extends MentornityModel {
  static decode(json) {
    const config = Object.assign(Object.create(Config.prototype), json);
    if (json.metadatas) {
      config.metadatas = new ConfigMetadatas();
      config.metadatas.mentor = (json.metadatas.mentor || []).map(field => generateFieldModelFromRawData(field));
      config.metadatas.mentee = (json.metadatas.mentee || []).map(field => generateFieldModelFromRawData(field));
    }
    return config;
  }
}
var InfoVisibility;
(function (InfoVisibility) {
  InfoVisibility["none"] = "none";
  InfoVisibility["subscribedOnly"] = "subscribedOnly";
  InfoVisibility["allMentees"] = "allMentees";
  InfoVisibility["allMentors"] = "allMentors";
  InfoVisibility["everyone"] = "everyone";
})(InfoVisibility || (InfoVisibility = {}));
class ConfigMetadatas {
}
class Invitation extends MentornityModel {
  constructor(init) {
    super();
    Object.assign(this, init);
  }
  static decode(json) {
    const invitation = Object.assign(Object.create(Invitation.prototype), json);
    if (json.createdBy.firstName) {
      invitation.createdBy = User.decode(json.createdBy);
    }
    if (json.invitee.firstName) {
      invitation.invitee = User.decode(json.invitee);
    }
    if (json.organisation.title) {
      invitation.organisation = Organisation.decode(json.organisation);
    }
    return invitation;
  }
}
var InvitationStatus;
(function (InvitationStatus) {
  InvitationStatus["Accepted"] = "accepted";
  InvitationStatus["Pending"] = "pending";
})(InvitationStatus || (InvitationStatus = {}));
class Metadata {
  static decode(json) {
    return Object.assign(Object.create(Metadata.prototype), json);
  }
}
class Event extends MentornityModel {
  static decode(json) {
    const event = Object.assign(Object.create(Event.prototype), json);
    // decode guests
    if (json.guests) {
      event.guests = json.guests.map((guest) => {
        if (guest.firstName) {
          return User.decode(guest);
        }
        else if (guest.title) {
          return Group.decode(guest);
        }
        else {
          return ModelReference.decode(guest);
        }
      });
    }
    if (json.createdBy && json.createdBy.firstName) {
      event.createdBy = User.decode(event.createdBy);
    }
    if (event.cancelInfo) {
      if (json.cancelInfo.canceledBy.firstName) {
        event.cancelInfo.canceledBy = User.decode(event.cancelInfo.canceledBy);
      }
      if (event.cancelInfo && event.cancelInfo.guestCausedCancellation) {
        if (event.cancelInfo.guestCausedCancellation.firstName) {
          event.cancelInfo.guestCausedCancellation = User.decode(event.cancelInfo.guestCausedCancellation);
        }
        else if (event.cancelInfo.guestCausedCancellation.title) {
          event.cancelInfo.guestCausedCancellation = Group.decode(event.cancelInfo.guestCausedCancellation);
        }
        else {
          event.cancelInfo.guestCausedCancellation = ModelReference.decode(event.cancelInfo.guestCausedCancellation);
        }
      }
    }
    return event;
  }
  ref() {
    return new ModelReference(this._id, Collection.Events);
  }
}
var EventStatus;
(function (EventStatus) {
  EventStatus["Active"] = "active";
  EventStatus["Canceled"] = "canceled";
})(EventStatus || (EventStatus = {}));
class Group extends MentornityModel {
  static decode(json) {
    const group = Object.assign(Object.create(Group.prototype), json);
    if (group.members) {
      for (let i = 0; i < group.members.length; i += 1) {
        if (group.members[i].firstName) {
          group.members[i] = User.decode(group.members[i]);
        }
      }
    }
    else {
      group.members = [];
    }
    if (json.organisation && json.organisation.title) {
      group.organisation = Organisation.decode(group.organisation);
    }
    else {
      group.organisation = ModelReference.decode(group.organisation);
    }
    if (json.subscriptions) {
      group.subscriptions = json.subscriptions.map((subscription) => {
        return Subscription.decode(subscription);
      });
    }
    return group;
  }
  ref() {
    return new ModelReference(this._id, Collection.Groups);
  }
  isSuite() {
    return this.type === 'mentor';
  }
}
class Mentorship extends MentornityModel {
  static decode(json) {
    const mentorship = Object.assign(Object.create(Mentorship.prototype), json);
    if (json.owner && json.owner.firstName) {
      mentorship.owner = User.decode(json.owner);
    }
    else {
      mentorship.owner = ModelReference.decode(json.owner);
    }
    return mentorship;
  }
  ref() {
    return new ModelReference(this._id, Collection.Mentorships);
  }
}
var NotePrivacy;
(function (NotePrivacy) {
  NotePrivacy["Private"] = "private";
  NotePrivacy["Public"] = "public";
})(NotePrivacy || (NotePrivacy = {}));
class Organisation extends MentornityModel {
  static decode(json) {
    return Object.assign(Object.create(Organisation.prototype), json);
  }
  ref() {
    return new ModelReference(this._id, Collection.Organisations);
  }
}
class User extends MentornityModel {
  constructor(data) {
    super();
    this._id = data._id;
    this.imageUrl = data.imageUrl;
    this.firstName = data.firstName;
    this.lastName = data.lastName;
    this.title = data.title;
    this.bio = data.bio;
  }
  static decode(json) {
    const user = Object.assign(Object.create(User.prototype), json);
    if (json.group) {
      user.group = Group.decode(json.group);
    }
    if (json.mentorship) {
      user.mentorship = Mentorship.decode(json.mentorship);
    }
    if (json.metadata) {
      user.metadata = Metadata.decode(json.metadata);
    }
    if (json.lastMeeting) {
      user.lastMeeting = Event.decode(json.lastMeeting);
    }
    if (json.subscriptions) {
      user.subscriptions = json.subscriptions.map((subscription) => {
        return Subscription.decode(subscription);
      });
    }
    if (json.events) {
      user.events = json.events.map((event) => {
        return Event.decode(event);
      });
    }
    return user;
  }
  ref() {
    return new ModelReference(this._id, Collection.Users);
  }
  getRolesInOrganisation(organisation) {
    const v = {
      isAdmin: false,
      isMentee: false,
      isMentor: false,
    };
    for (const role of this._roles) {
      if (role.indexOf('@') === -1) {
        // skip if not organisation role
        continue;
      }
      const roleInfo = role.split('@');
      const userRole = roleInfo[0];
      const domain = roleInfo[1];
      if (domain === organisation.domain) {
        if (userRole === 'admin') {
          v.isAdmin = true;
        }
        else if (userRole === 'mentee') {
          v.isMentee = true;
        }
        else if (userRole === 'mentor') {
          v.isMentor = true;
        }
      }
    }
    return v;
  }
  isAdminOfAnyOrganisation() {
    for (const role of this._roles) {
      if (role.indexOf('@') === -1) {
        // skip if not organisation role
        continue;
      }
      const roleInfo = role.split('@');
      const userRole = roleInfo[0];
      if (userRole === 'admin') {
        return true;
      }
    }
    return false;
  }
  getMetadataValue(id) {
    if (!this.metadata || !this.metadata.data) {
      return undefined;
    }
    return this.metadata.data[id];
  }
}
var UserStatus;
(function (UserStatus) {
  UserStatus["Active"] = "active";
  UserStatus["Invited"] = "invited";
  UserStatus["NotInvited"] = "notInvited";
})(UserStatus || (UserStatus = {}));
class Subscription extends MentornityModel {
  static decode(json) {
    const subscription = Object.assign(Object.create(Subscription.prototype), json);
    if (json.organisation && json.organisation.title) {
      subscription.organisation = Organisation.decode(subscription.organisation);
    }
    else {
      subscription.organisation = ModelReference.decode(subscription.organisation);
    }
    if (json.mentorship) {
      subscription.mentorship = Mentorship.decode(json.mentorship);
    }
    else {
      subscription.mentorship = ModelReference.decode(json.mentorship);
    }
    if (json.subscriber && json.subscriber.firstName) {
      subscription.subscriber = User.decode(json.subscriber);
    }
    else if (json.subscriber && json.subscriber.title) {
      subscription.subscriber = Group.decode(json.subscriber);
    }
    else {
      subscription.subscriber = ModelReference.decode(json.subscriber);
    }
    return subscription;
  }
}
var FormType;
(function (FormType) {
  FormType["Application"] = "application";
  FormType["Survey"] = "survey";
  FormType["PostSubscriptionFeedback"] = "postSubscriptionFeedback";
})(FormType || (FormType = {}));
var FormTarget;
(function (FormTarget) {
  FormTarget["All"] = "all";
  FormTarget["Mentee"] = "mentee";
  FormTarget["Mentor"] = "mentor";
})(FormTarget || (FormTarget = {}));
var FormStatus;
(function (FormStatus) {
  FormStatus["Published"] = "published";
  FormStatus["Unpublished"] = "unpublished";
})(FormStatus || (FormStatus = {}));
class ViewConfigWrapper extends MentornityModel {
  static decode(json) {
    return Object.assign(Object.create(ViewConfigWrapper.prototype), json);
  }
}
var MentornityViewConfigViewName;
(function (MentornityViewConfigViewName) {
  MentornityViewConfigViewName["MentorApplicationForm"] = "mentor-application-form";
  MentornityViewConfigViewName["MentorInfoForm"] = "mentor-info-form";
  MentornityViewConfigViewName["MentorCardList"] = "mentor-card-list";
  MentornityViewConfigViewName["MentorCardListDetail"] = "mentor-card-list-detail";
  // MentorCardListFilter = 'mentor-card-list-filter',
  MentornityViewConfigViewName["MentorDetail"] = "mentor-detail";
  MentornityViewConfigViewName["MentorDetailSummary"] = "mentor-detail-summary";
  MentornityViewConfigViewName["MentorSelectionList"] = "mentor-selection-list";
  MentornityViewConfigViewName["MentorSelectionListDetail"] = "mentor-selection-list-detail";
  // MentorSelectionListFilter = 'mentor-selection-list-detail',
  MentornityViewConfigViewName["MentorPairList"] = "mentor-pair-list";
  MentornityViewConfigViewName["MentorPairDetail"] = "mentor-pair-detail";
  // MentorPairDetailSummary = 'mentor-pair-detail-summary',
  MentornityViewConfigViewName["MenteeApplicationForm"] = "mentee-application-form";
  MentornityViewConfigViewName["MenteeInfoForm"] = "mentee-info-form";
  MentornityViewConfigViewName["MenteeCardList"] = "mentee-card-list";
  MentornityViewConfigViewName["MenteeCardListDetail"] = "mentee-card-list-detail";
  // MenteeCardListFilter = 'mentee-card-list-filter',
  MentornityViewConfigViewName["MenteeDetail"] = "mentee-detail";
  // MenteeDetailSummary = 'mentee-detail-summary',
  MentornityViewConfigViewName["MenteePairList"] = "mentee-pair-list";
  MentornityViewConfigViewName["MenteePairDetail"] = "mentee-pair-detail";
  MentornityViewConfigViewName["MenteePairDetailSummary"] = "mentee-pair-detail-summary";
})(MentornityViewConfigViewName || (MentornityViewConfigViewName = {}));

function generateQueryParams(query = {}, skip = 0, sort = '', limit = 25) {
  const params = Object.assign(Object.assign({}, query), { skip,
    limit });
  if (sort && sort != '') {
    params.sort = sort;
  }
  return params;
}
class MentornityApi {
  constructor(endpoint, defaultHeaders = {}) {
    // region common
    this.create = (collection, body) => this.api.post(collection, body);
    this.find = (collection, params) => this.api.get(`${collection}`, params);
    this.get = (collection, id, params) => this.api.get(`${collection}/${id}`, params);
    this.update = (collection, id, body) => this.api.put(`${collection}/${id}`, body);
    this.delete = (collection, id) => this.api.delete(`${collection}/${id}`);
    // endregion
    // region session
    /**
     * Used to gets session data. Returns only white label info if there is no account.
     *
     * @param domain of the current web site. (used to determine the white label)
     */
    this.getSessionData = (domain) => this.api.get(`sessionData?domain=${domain}`);
    // endregion
    // region organisation
    this.getOrganisation = (organisationId) => this.api.get(`organisations/${organisationId}`);
    this.getOrganisationConfig = (organisationId) => this.api.get(`organisations/${organisationId}/config`);
    this.getOrganisationMeetingGoalConfig = (organisationId) => this.api.get(`organisations/${organisationId}/meetingGoalConfig`);
    this.getViewConfigs = (organisationId) => this.api.get(`organisations/${organisationId}/view-configs`);
    this.getViewConfig = (organisationId, viewName) => this.api.get(`organisations/${organisationId}/view-configs/${viewName}`);
    this.createViewConfig = (viewConfigWrapper) => this.api.post('view-configs', viewConfigWrapper);
    this.updateViewConfig = (id, viewConfigWrapper) => this.api.put(`view-configs/${id}`, viewConfigWrapper);
    // endregion
    this.createInvitation = (data) => this.api.post('invitations', data);
    // region members
    this.getMentees = (organisationId, query = {}, skip = 0, sort = '', limit) => this.api.get(`organisations/${organisationId}/mentees`, generateQueryParams(query, skip, sort, limit));
    this.getMentors = (organisationId, query = {}, skip = 0, sort = '', limit) => this.api.get(`organisations/${organisationId}/mentors`, generateQueryParams(query, skip, sort, limit));
    this.getMentorshipOfUser = (organisationId, userId) => this.api.get(`organisations/${organisationId}/mentors/${userId}/mentorship`);
    this.getMembershipApplicationForm = (organisationId, role) => this.api.get(`organisations/${organisationId}/${role}/applications/form`);
    this.createMembershipApplication = (organisationId, role, data) => this.api.post(`organisations/${organisationId}/${role}/applications`, data);
    // endregion
    // region metadatas
    this.getMetadataOfUser = (organisationId, role, userId) => this.api.get(`organisations/${organisationId}/${role}/${userId}/metadata`);
    // endregion
    // region subscriptions
    this.getOrganisations = (query = {}, skip = 0, sort = '', limit) => this.api.get(`organisations`, generateQueryParams(query, skip, sort, limit));
    this.createSubscription = (subscription) => this.api.post(`subscriptions`, subscription);
    this.followUnfollowSubscription = (subscriptionId, action) => this.api.post(`subscriptions/${subscriptionId}/${action}`, {});
    // endregion
    // region subscriptions
    this.getSubscriptionsOfMentors = (id, query = {}, skip = 0, sort = '', limit) => this.api.get(`organisations/${id}/mentors`, generateQueryParams(Object.assign(Object.assign({}, query), { appendSubscriptions: true }), skip, sort, limit));
    this.completeSubscription = (subscriptionId) => this.api.put(`${Collection.Subscriptions}/${subscriptionId}`, { status: 'completed' });
    this.deleteSubscription = (subscriptionId) => this.api.delete(`${Collection.Subscriptions}/${subscriptionId}`);
    // endregion
    this.getMeetingsInMeetingGoal = (id, query = {}, skip = 0, sort = '', limit) => this.api.get(`organisations/${id}/meetingsInMeetingGoal`, generateQueryParams(query, skip, sort, limit));
    this.createForm = (data) => this.api.post('forms', data);
    this.api = new APIBase(endpoint, defaultHeaders);
  }
  cloneOrganisation(body) {
    return this.api.post('organisations/clone', body);
  }
  importUser(id, userType, body) {
    return this.api.post(`organisations/${id}/${userType}/import`, body);
  }
  removeOrganisationAdmin(userId, body) {
    return this.api.post(`users/${userId}/recallRole`, body);
  }
  changeOrganisationDomain({ domain, organisationId }) {
    return this.api.put(`organisations/${organisationId}/domain`, { domain });
  }
}

let apiInstance;
function createMentornityApiInstance(endpoint, defaultHeaders = {}) {
  apiInstance = new MentornityApi(endpoint, defaultHeaders);
  return apiInstance;
}

export { Collection as C, FormStatus as F, Invitation as I, ModelReference as M, ViewConfigWrapper as V, InvitationStatus as a, MentornityViewConfigViewName as b, createMentornityApiInstance as c, ConfigMentorMenteeSubscription as d, InfoVisibility as e, Config as f };
