// App
// -----------------------------------------------------------------------------
import {
  CorrelationRulesRecord,
  CorrelationRulesRecordForBackend,
} from 'types/default';
import { DownloadFile } from 'services/FileDownload';
import { GenericDataStore } from './GenericDataStore';
import { environment } from 'enviroments/enviroments';

export class CorrelationRulesStore extends GenericDataStore<
  CorrelationRulesRecord,
  CorrelationRulesRecordForBackend
> {
  constructor() {
    super(environment.correlations.rules);
    this.override();
  }

  getId = (entity: CorrelationRulesRecord): number => entity.id;

  getName = (entity: CorrelationRulesRecord): string => entity.name;

  prepareDataForBackend = (
    entity: CorrelationRulesRecord,
  ): CorrelationRulesRecordForBackend => {
    return { ...entity, group: entity?.group?.id ?? null };
  };

  async exportData(): Promise<void> {
    await DownloadFile(environment.correlations.rulesExport);
  }

  async importData(data: any): Promise<void> {
    await DownloadFile(environment.correlations.rulesImport, 'POST', data);
  }
}
