import { Injectable } from '@angular/core';
import { ChartConfig } from '../chart-config';
import { IData } from '../chart-type';
import { DatasetService } from './dataset.service';
import { LabelService } from './label.service';
import { OptionsService } from './options.service';

@Injectable()
export class ChartConfigService {
  constructor(
    private datasetService: DatasetService,
    private labelService: LabelService,
    private optionsService: OptionsService
  ) {}

  chart(chart: ChartConfig, data: Record<string, any>[]): any {
    return {
      type: chart?.type,
      data: this.data(chart, data),
      options: this.optionsService.options(chart, data),
    } as any;
  }

  private data(chart: ChartConfig, data: Record<string, any>[]): IData {
    return {
      labels: this.labelService.labels(chart, data),
      datasets: this.datasetService.datasets(chart, data),
    } as IData;
  }
}
