import { RootStore } from 'stores/RootStore';
import { action, makeAutoObservable, toJS } from 'mobx';
import { IRotationSettings } from 'types/default';
import { TRotationSettingSubmit } from './types';

export class RotationUiStore {
  constructor(private readonly rootStore: RootStore) {
    makeAutoObservable(this);
  }

  get incidents(): IRotationSettings | null {
    return toJS(this.rootStore.rotationStore.rotationIncidents);
  }

  get events(): IRotationSettings | null {
    return toJS(this.rootStore.rotationStore.rotationEvents);
  }

  get loading(): boolean {
    return this.rootStore.rotationStore.getLoading;
  }

  @action loadingRotationIncident = (): void => {
    this.rootStore.rotationStore.getRotationIncidents();
  };

  @action loadingRotationEvent = (): void => {
    this.rootStore.rotationStore.getRotationEvents();
  };

  @action uploadRotationIncident = (
    data: TRotationSettingSubmit,
    translation: { messageTitle: string; messageDescription: string },
  ): void => {
    this.rootStore.rotationStore.postRotationIncidents(data, translation);
  };

  @action uploadRotationEvent = (
    data: TRotationSettingSubmit,
    translation: { messageTitle: string; messageDescription: string },
  ): void => {
    this.rootStore.rotationStore.postRotationEvents(data, translation);
  };
}
