'use strict';

const BaseField = require('./BaseField-f50bb8f0.js');
const instance = require('./instance-fbedf46d.js');
const pairConfig$1 = require('./pair-config-a5d7c3eb.js');

/**
 * This configuration is used to satisfy the pair configuration that is required by the Devingen app.
 * The values here represents the 'subscription' model used in Mentornity and some new fields are added on top of that.
 */
const pairConfig = (organisationConfig, goalConfig, options) => {
  var _a;
  return pairConfig$1.PairConfig.decode({
    actionPermissions: {
      subscriber: {
        completePair: false,
      },
      subscribed: {
        completePair: !!(options === null || options === void 0 ? void 0 : options.canMentorEndSubscription),
      },
    },
    fields: [
      {
        type: 'reference',
        id: 'subscriber',
        otherCollection: organisationConfig.menteeType === 'group' ? 'groups' : 'mentees',
      },
      {
        type: 'reference',
        id: 'subscribed',
        otherCollection: 'mentors',
      },
    ],
    selection: organisationConfig.menteeType === 'group' ? undefined : {
      subscriber: {
        initiation: 'approvingly',
        pairLimit: options === null || options === void 0 ? void 0 : options.pairLimitForMentees,
        selectionLimit: options === null || options === void 0 ? void 0 : options.selectionLimitForMentees,
        roleNameToSelect: 'subscribed',
        rules: [
          new pairConfig$1.Rule([
            {
              firstField: BaseField.BaseField.decode({ id: 'city', type: 'text' }),
              comparison: pairConfig$1.Comparison.eq,
              secondField: BaseField.BaseField.decode({ id: 'city', type: 'text' }),
            }
          ], pairConfig$1.RuleType.comparison),
        ],
        selectionUI: {
          showMessageButton: [
            instance.InfoVisibility.allMentors,
            instance.InfoVisibility.everyone,
          ].includes(organisationConfig.conversationPermissions.mentee),
        },
        status: (options === null || options === void 0 ? void 0 : options.isMentorSelectionOn) ? 'active' : 'passive',
      },
    },
    structure: goalConfig ? {
      meetingConfigs: ((_a = goalConfig.meetingGoals) === null || _a === void 0 ? void 0 : _a.map(meetingConfig => ({
        id: meetingConfig.identifier,
        name: meetingConfig.meetingTitle,
        meetingCount: 1,
        specifications: {
          subscriber: meetingConfig.specifications.mentee,
          subscribed: meetingConfig.specifications.mentor,
        },
      }))) || [],
    } : undefined
  });
};

exports.pairConfig = pairConfig;
