import { Observable } from 'rxjs';
import { JumpResp } from './jump';

export enum StatType {
  ForLastMonth = 1,
  ForLastYear = 2,
  ByDz = 3,
  ByAircraft = 4,
  ByGear = 5,
  ByJumpType = 6,
  ByYear = 7,
}

export class StatsResp {
  public simpleSummary: Observable<SimpleSummary>;

  public statsByDz: Observable<Array<StatsByDzResp>>;
  public statsByAircraft: Observable<Array<StatsByAircraftResp>>;
  public statsByGear: Observable<Array<StatsByGearResp>>;
  public statsByJumpType: Observable<Array<StatsByJumpTypeResp>>;
  public statsByYear: Observable<Array<StatsByYearResp>>;

  public statsForLastYear: Observable<StatsForLastYearResp>;
  public statsForLastMonth: Observable<StatsForLastMonthResp>;
}

export class SimpleSummary {
  constructor(data: any) {
    this.totalJumps = data.totalJumps;
    this.totalCutaways = data.totalCutaways;

    if (data.lastJump !== null) {
      this.lastJump = new JumpResp(data.lastJump);
    }
  }

  public totalJumps: number;
  public totalCutaways: number;
  public lastJump: JumpResp;
}

export class StatsByDzResp {
  constructor(data: any) {
    Object.assign(this, data);
  }

  public label: string;
  public nb: number;
}

export class StatsByAircraftResp {
  constructor(data: any) {
    Object.assign(this, data);
  }

  public label: string;
  public nb: number;
}

export class StatsByGearResp {
  constructor(data: any) {
    Object.assign(this, data);
  }

  public label: string;
  public nb: number;
}

export class StatsByJumpTypeResp {
  constructor(data: any) {
    Object.assign(this, data);
  }

  public label: string;
  public nb: number;
}

export class StatsByYearResp {
  constructor(data: any) {
    Object.assign(this, data);
  }

  public label: string;
  public nb: number;
}

export class StatsForLastYearResp {
  constructor(dataByDz: Array<StatsByDzResp>,
              dataByJumpType: Array<StatsByJumpTypeResp>) {
    this.byDz = new Array<StatsByDzResp>();
    this.byJumpType = new Array<StatsByJumpTypeResp>();

    Object.assign(this.byDz, dataByDz);
    Object.assign(this.byJumpType, dataByJumpType);
  }

  public byDz: Array<StatsByDzResp>;
  public byJumpType: Array<StatsByJumpTypeResp>;
}

export class StatsForLastMonthResp {
  constructor(dataByDz: Array<StatsByDzResp>,
              dataByJumpType: Array<StatsByJumpTypeResp>) {
    this.byDz = new Array<StatsByDzResp>();
    this.byJumpType = new Array<StatsByJumpTypeResp>();

    Object.assign(this.byDz, dataByDz);
    Object.assign(this.byJumpType, dataByJumpType);
  }

  public byDz: Array<StatsByDzResp>;
  public byJumpType: Array<StatsByJumpTypeResp>;
}
