// TODO types, interfaces

import { configCreator } from './config';
import { AxiosResponse } from 'axios';
import { DomainApi, RestDaysApi, RestDay, Notification } from '@openapi/idm';

class IdmServiceDomains {
  public getDomainNotifications({ id, expand }: any): Promise<Notification[]> {
    return new Promise((resolve, reject) => {
      configCreator().then((config) => {
        new DomainApi(config)
          .getNotifications(id, expand)
          .then((resp: AxiosResponse) => {
            resolve(resp.data);
          })
          .catch((e: Error) => {
            console.error(
              `[services/idm/getDomainNotifications] - ${e.toString()}`
            );
            reject(e);
          });
      });
    });
  }

  public getDomainRestDays({ id }: any): Promise<RestDay[]> {
    return new Promise((resolve, reject) => {
      configCreator().then((config) => {
        new RestDaysApi(config)
          .mergedCalendar(id)
          .then((resp: AxiosResponse) => {
            resolve(resp.data);
          })
          .catch((e: Error) => {
            console.error(`[services/idm/getDomainRestDays] - ${e.toString()}`);
            reject(e);
          });
      });
    });
  }
}

export default new IdmServiceDomains();
