// tslint:disable:variable-name
var __rest = (this && this.__rest) || function (s, e) {
  var t = {};
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
    t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
import { BaseField } from '@dvn/core/doldurma/src/BaseField';
import { generateFieldModelFromRawData } from '@dvn/core/doldurma/src/FieldModelGenerator';
export function clone(obj) {
  return JSON.parse(JSON.stringify(obj));
}
export var Role;
(function (Role) {
  Role["Admin"] = "admin";
  Role["Mentee"] = "mentee";
  Role["Mentor"] = "mentor";
})(Role || (Role = {}));
export 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 = {}));
export class MentornityModel {
  Id() {
    return this._id;
  }
}
export 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);
  }
}
export class Activity extends MentornityModel {
  static decode(json) {
    const activity = Object.assign(Object.create(Activity.prototype), json);
    if (activity.on) {
      if (activity.on.firstName) {
        activity.on = User.decode(activity.on);
      }
      else if (activity.on.guests) {
        activity.on = Event.decode(activity.on);
      }
    }
    if (activity.object) {
      if (activity.object.guests) {
        activity.object = Event.decode(activity.object);
      }
      else if (activity.object.slots) {
        activity.object = Availability.decode(activity.object);
      }
      else if (activity.object.content) {
        activity.object = Note.decode(activity.object);
      }
    }
    activity.subject = User.decode(activity.subject);
    return activity;
  }
}
export 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 = {}));
export class Announcement extends MentornityModel {
  static decode(json) {
    return Object.assign(Object.create(Announcement.prototype), json);
  }
}
export var AnnouncementStatus;
(function (AnnouncementStatus) {
  AnnouncementStatus["Published"] = "published";
  AnnouncementStatus["Unpublished"] = "unpublished";
})(AnnouncementStatus || (AnnouncementStatus = {}));
export var AnnouncementTarget;
(function (AnnouncementTarget) {
  AnnouncementTarget["All"] = "all";
  AnnouncementTarget["Mentee"] = "mentee";
  AnnouncementTarget["Mentor"] = "mentor";
})(AnnouncementTarget || (AnnouncementTarget = {}));
export class Availability extends MentornityModel {
  static decode(json) {
    return Object.assign(Object.create(Availability.prototype), json);
  }
  ref() {
    return new ModelReference(this._id, Collection.Events);
  }
}
export class Slot {
}
export class AuthPlatform {
  static decode(json) {
    return Object.assign(Object.create(AuthPlatform.prototype), json);
  }
}
export var ConfigMenteeType;
(function (ConfigMenteeType) {
  ConfigMenteeType["Individual"] = "individual";
  ConfigMenteeType["Group"] = "group";
  ConfigMenteeType["GroupedIndividual"] = "groupedIndividual";
})(ConfigMenteeType || (ConfigMenteeType = {}));
export var ConfigMentorMenteeSubscription;
(function (ConfigMentorMenteeSubscription) {
  ConfigMentorMenteeSubscription["Implicit"] = "implicit";
  ConfigMentorMenteeSubscription["Restricted"] = "restricted";
})(ConfigMentorMenteeSubscription || (ConfigMentorMenteeSubscription = {}));
export 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;
  }
}
export var InfoVisibility;
(function (InfoVisibility) {
  InfoVisibility["none"] = "none";
  InfoVisibility["subscribedOnly"] = "subscribedOnly";
  InfoVisibility["allMentees"] = "allMentees";
  InfoVisibility["allMentors"] = "allMentors";
  InfoVisibility["everyone"] = "everyone";
})(InfoVisibility || (InfoVisibility = {}));
export class Conversation extends MentornityModel {
  static decode(json) {
    const conversation = Object.assign(Object.create(Conversation.prototype), json);
    if (json.organisation.title) {
      conversation.organisation = Organisation.decode(json.organisation);
    }
    // decode participants
    conversation.participants = conversation.participants.map((guest) => {
      if (guest.firstName) {
        return User.decode(guest);
      }
      else {
        return ModelReference.decode(guest);
      }
    });
    return conversation;
  }
}
export class FormData {
  constructor(fields, showFieldOrder, version) {
    this.fields = fields;
    this.showFieldOrder = showFieldOrder;
    this.version = version;
    if (!version) {
      this.version = 0.1;
    }
  }
}
export class FeedbackConfig {
}
export class ConfigActivityRules {
}
export class AdminHomeMessage {
}
export class ConfigMetadatas {
}
export class Feedback extends MentornityModel {
  static decode(json) {
    const feedback = Object.assign(Object.create(Feedback.prototype), json);
    if (json.createdBy.firstName) {
      feedback.createdBy = User.decode(json.createdBy);
    }
    if (json.event.startDate) {
      feedback.event = Event.decode(json.event);
    }
    return feedback;
  }
}
export 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;
  }
}
export var InvitationStatus;
(function (InvitationStatus) {
  InvitationStatus["Accepted"] = "accepted";
  InvitationStatus["Pending"] = "pending";
})(InvitationStatus || (InvitationStatus = {}));
export class Metadata {
  static decode(json) {
    return Object.assign(Object.create(Metadata.prototype), json);
  }
}
export class ConfigRoutes {
}
export class ConfigTermReplacements {
}
export class Context {
  static decode(json) {
    const { config, organisation, meetingGoalConfig } = json, rest = __rest(json, ["config", "organisation", "meetingGoalConfig"]);
    return Object.assign(Object.create(Context.prototype), rest, {
      config: Config.decode(config),
      meetingGoalConfig: (meetingGoalConfig && meetingGoalConfig._id) && MeetingGoalConfig.decode(meetingGoalConfig),
      organisation: Organisation.decode(organisation),
    });
  }
}
export 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);
  }
}
export class EventCancelInfo {
}
export var EventStatus;
(function (EventStatus) {
  EventStatus["Active"] = "active";
  EventStatus["Canceled"] = "canceled";
})(EventStatus || (EventStatus = {}));
export 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';
  }
}
export class Location {
}
export class MeetingGoal {
}
export class MeetingGoalSpecification {
}
export class MeetingGoalForms {
}
export class MeetingGoalConfig extends MentornityModel {
  static decode(json) {
    return Object.assign(Object.create(MeetingGoalConfig.prototype), json);
  }
}
export 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);
  }
}
export class Message extends MentornityModel {
  static decode(json) {
    const message = Object.assign(Object.create(Message.prototype), json);
    if (json.createdBy.firstName) {
      message.createdBy = User.decode(json.createdBy);
    }
    else {
      message.createdBy = ModelReference.decode(json.createdBy);
    }
    message.conversation = ModelReference.decode(message.conversation);
    return message;
  }
}
export class Note extends MentornityModel {
  static decode(json) {
    const note = Object.assign(Object.create(Note.prototype), json);
    if (json.createdBy.firstName) {
      note.createdBy = User.decode(json.createdBy);
    }
    return note;
  }
}
export var NotePrivacy;
(function (NotePrivacy) {
  NotePrivacy["Private"] = "private";
  NotePrivacy["Public"] = "public";
})(NotePrivacy || (NotePrivacy = {}));
export class Organisation extends MentornityModel {
  static decode(json) {
    return Object.assign(Object.create(Organisation.prototype), json);
  }
  ref() {
    return new ModelReference(this._id, Collection.Organisations);
  }
}
export class OrganisationSubscriptionsSummary {
}
export class OrganisationSummary {
  static decode(json) {
    return Object.assign(Object.create(OrganisationSummary.prototype), json);
  }
}
export class OrganisationSummaryMetrics {
}
export class BaseFieldRule {
}
export class SubscriptionConfig {
}
export class SubscriptionRule extends BaseField {
}
export 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];
  }
}
export var UserStatus;
(function (UserStatus) {
  UserStatus["Active"] = "active";
  UserStatus["Invited"] = "invited";
  UserStatus["NotInvited"] = "notInvited";
})(UserStatus || (UserStatus = {}));
export class Settings extends MentornityModel {
  static decode(json) {
    return Object.assign(Object.create(Settings.prototype), json);
  }
}
export 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;
  }
}
export class FormModel extends MentornityModel {
  static decode(json) {
    return Object.assign(Object.create(FormModel.prototype), json);
  }
  ref() {
    return new ModelReference(this._id, Collection.Forms);
  }
}
export class FormResponse extends MentornityModel {
  static decode(json) {
    return Object.assign(Object.create(FormResponse.prototype), json);
  }
}
export var FormType;
(function (FormType) {
  FormType["Application"] = "application";
  FormType["Survey"] = "survey";
  FormType["PostSubscriptionFeedback"] = "postSubscriptionFeedback";
})(FormType || (FormType = {}));
export var FormTarget;
(function (FormTarget) {
  FormTarget["All"] = "all";
  FormTarget["Mentee"] = "mentee";
  FormTarget["Mentor"] = "mentor";
})(FormTarget || (FormTarget = {}));
export var FormStatus;
(function (FormStatus) {
  FormStatus["Published"] = "published";
  FormStatus["Unpublished"] = "unpublished";
})(FormStatus || (FormStatus = {}));
export class ViewConfigWrapper extends MentornityModel {
  static decode(json) {
    return Object.assign(Object.create(ViewConfigWrapper.prototype), json);
  }
}
export 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 = {}));
