import { DataModel } from '@dvn/core/models/data-model';
import { notImplemented } from '@dvn/dvn-mock/api/utils';
import { User } from '@dvn/kimlik/api/models';
export class AtamaApiDemo {
  constructor(database, logger) {
    this.logger = logger.new('AtamaApiDemo').setColor('carrot');
    this.database = database;
  }
  addAuthInterceptor(token) {
    this.logger.debugGroup('addAuthInterceptor', token);
  }
  getPairsOfUser(base, collection, userRefFieldId, userRefFieldValue) {
    this.logger.debugGroup('getPairsOfUser', { base, collection, userRefFieldId, userRefFieldValue });
    const table = this.database[collection];
    if (!table) {
      this.logger.warnGroup('getPairsOfUser: table not found', { base, collection, userRefFieldId, userRefFieldValue });
      return Promise.reject(`AtamaApiDemo.getPairsOfUser: Table "${collection}" not found`);
    }
    const results = Object.keys(table).map(id => table[id]).filter(m => m[userRefFieldId][0]._id === userRefFieldValue);
    return Promise.resolve({
      results,
      meta: { total: results.length, base }
    });
  }
  // TODO make this function use the actual parameters to return this demo data
  getSelectionList(base, collection, pairConfigId, userRefFieldId, memberToViewRefFieldId) {
    this.logger.debugGroup('getSelectionList', { base, collection, pairConfigId, userRefFieldId, memberToViewRefFieldId });
    // return all mentees directly
    return Promise.resolve({
      results: Object.keys(this.database.uyeMembershipsMentors).map(id => this.database.uyeMembershipsMentors[id]),
      meta: { total: 2, base, query: {} }
    });
  }
  // TODO make this function use the actual parameters to return this demo data
  getSentRequests(base, collection, userRefFieldValue) {
    this.logger.debugGroup('getSentRequests', { base, collection, userRefFieldValue });
    return new Promise(resolve => {
      setTimeout(() => {
        resolve({
          results: Object.keys(this.database.uyeMembershipsMentors)
            .map(id => this.database.uyeMembershipsMentors[id])
            .map((m, i) => DataModel.decode({
            status: i % 2 == 0 ? 'pending' : 'rejected',
            sentTo: User.decode(m.user),
          })),
          meta: { total: 2 }
        });
      }, 200);
    });
  }
  // TODO make this function use the actual parameters to return this demo data
  getReceivedRequests(base, collection) {
    this.logger.debugGroup('getReceivedRequests', { base, collection });
    return new Promise(resolve => {
      setTimeout(() => {
        resolve({
          results: Object.keys(this.database.uyeMembershipsMentors)
            .map(id => this.database.uyeMembershipsMentors[id])
            .map((m, i) => DataModel.decode({
            status: i % 2 == 0 ? 'pending' : 'rejected',
            sentTo: User.decode(m.user),
          })),
          meta: { total: 2 }
        });
      }, 200);
    });
  }
  getMeetingsOfUser(base, collection, structureId, userRefFieldValue) {
    this.logger.debugGroup('getMeetingsOfUser', { base, collection, structureId, userRefFieldValue });
    return Promise.reject(notImplemented('getMeetingsOfUser'));
  }
  endPair(base, collection, pairId) {
    // console.log(base, collection, userRefFieldId, userRefFieldValue);
    this.logger.debugGroup('endPair', { base, collection, pairId });
    return Promise.reject(notImplemented('endPair'));
  }
  sendPairRequest(base, collection, userRefFieldId, userRefFieldValue, memberToViewRefFieldId, memberToViewData) {
    this.logger.debugGroup('sendPairRequest', { base, collection, userRefFieldId, userRefFieldValue, memberToViewRefFieldId, memberToViewData });
    return Promise.reject(notImplemented('sendPairRequest'));
  }
  acceptPairRequest(base, collection, requestId) {
    this.logger.debugGroup('acceptPairRequest', { base, collection, requestId });
    return Promise.reject(notImplemented('acceptPairRequest'));
  }
  rejectPairRequest(base, collection, requestId) {
    this.logger.debugGroup('rejectPairRequest', { base, collection, requestId });
    return Promise.reject(notImplemented('rejectPairRequest'));
  }
}
