import { BaseField } from '@dvn/core/doldurma/src/BaseField';
import { PairConfig } from '@dvn/core/models/pair-config';
import { Comparison, Rule, RuleType } from '@dvn/core/models/rule';
import { InfoVisibility } from '../../../mentornity-js-client/models';
/**
 * 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.
 */
export const pairConfig = (organisationConfig, goalConfig, options) => {
  var _a;
  return 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 Rule([
            {
              firstField: BaseField.decode({ id: 'city', type: 'text' }),
              comparison: Comparison.eq,
              secondField: BaseField.decode({ id: 'city', type: 'text' }),
            }
          ], RuleType.comparison),
        ],
        selectionUI: {
          showMessageButton: [
            InfoVisibility.allMentors,
            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
  });
};
