import { TEMPERATURE, HUMIDITY, TYPE, VALUE } from "../const";

import { Colors } from "./Utils";

export class Serie {
  private _type: string;
  private _data: { time: number; value: Date }[];

  private _user: string;
  private _room: string;
  private _device: string;

  constructor(
    type: string,
    data: { time: number; value: Date }[],
    user: string,
    room: string,
    device: string
  ) {
    this._type = type;
    this._data = data;
    this._user = user;
    this._room = room;
    this._device = device;
  }

  public getLabel(): String {
    if (this._type === TEMPERATURE) {
      return "Temperature [°C]";
    } else if (this._type === HUMIDITY) {
      return "Humidity [%]";
    } else {
      return "Unknown";
    }
  }

  public getSerie(): any {
    if (this._type === TEMPERATURE) {
      return {
        label: this.getLabel(),
        data: this._data.map((v: any) => {
          return { x: v.time, y: v.value };
        }),
        borderColor: Colors.BLUE,
        backgroundColor: Colors.BLUE,
        borderWidth: 1,
        yAxisID: TEMPERATURE,
      };
    } else if (this._type === HUMIDITY) {
      return {
        label: this.getLabel(),
        data: this._data.map((v: any) => {
          return { x: v.time, y: v.value };
        }),
        borderColor: Colors.GREEN,
        backgroundColor: Colors.GREEN,
        borderWidth: 1,
        yAxisID: HUMIDITY,
      };
    } else {
      return {
        label: "Unknown",
        data: this._data.map((v: any) => {
          return { x: v.time, y: v.value };
        }),
        borderColor: Colors.RED,
        backgroundColor: Colors.RED,
        borderWidth: 1,
        yAxisID: TEMPERATURE,
      };
    }
  }
}
