import { APIBase } from '@dvn/core/api/apiBase';
import { DataModel } from '@dvn/core/models/data-model';
export class MentornityAnnouncementsWrapperBridgeApi {
  constructor(organisationId, endpoint, headers, language, strings) {
    this.client = new APIBase(endpoint, headers);
    this.organisationId = organisationId;
    this.language = language;
    this.strings = strings;
  }
  addAuthInterceptor(_token) {
    // console.log('MBA.addAuthInterceptor', token);
  }
  // region DataApi
  get(_collection, _id, _query) {
    return undefined;
  }
  query() {
    return new Promise((resolve => {
      this.client.get(`organisations/${this.organisationId}/announcements`).then(response => {
        resolve({
          results: response.results.map((item) => DataModel.decode(Object.assign(Object.assign({ _id: item._id }, (item || {})), { createdAt: item.createdAt * 1000, recipients: this.strings[item.target], status: item.status, 
            // inserted for sub components
            language: this.language }))),
          meta: {
            total: response.results.length,
          }
        });
      }).catch(e => {
        console.log(e);
      });
    }));
  }
  update(_collection, _id, _body) {
    return undefined;
  }
}
