/* eslint-disable object-curly-newline */
import type { Elements as ElementsActions } from 'Components/Calculation/config/map/actions';
import type { Elements as ElementsValues } from 'Components/Calculation/config/map/values';
import defaultStatuses from 'config/default-statuses';
import { makeAutoObservable } from 'mobx';
import type RootStore from 'stores/root';
import type { Status } from 'ui/elements/types';
import type { CalculationStatuses } from './types';

export default class StatusStore {
  root: RootStore;
  statuses: CalculationStatuses = defaultStatuses;

  constructor(rootStore: RootStore) {
    makeAutoObservable(this);
    this.root = rootStore;
  }

  hydrate = (initialStatuses: CalculationStatuses) => {
    this.statuses = initialStatuses;
  };

  getStatus(elementName: ElementsValues | ElementsActions) {
    return this.statuses[elementName];
  }

  setStatus = (elementName: ElementsValues | ElementsActions, status: Status) => {
    this.statuses[elementName] = status;
  };

  resetStatus = (elementName: ElementsValues | ElementsActions) => {
    this.statuses[elementName] = defaultStatuses[elementName];
  };
}
