import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { ApiService } from '../api.service';
import { CanopyBySize, CanopyByYear, CanopyModelBySize, CanopyModelByYear } from '@models';

@Injectable({ providedIn: 'root' })
export class CanopiesService {
    private _apiVersion = '/v1';
    constructor(
        private apiService: ApiService
    ) { }

    getAllBySize(): Observable<Array<CanopyBySize>> {
        return this.apiService.get(`${this._apiVersion}/canopies/allBySize`)
            .pipe(map(data => data.canopies));
    }

    getAllBySizeByYear(): Observable<Array<CanopyByYear>> {
        return this.apiService.get(`${this._apiVersion}/canopies/allBySizeByYear`)
            .pipe(map(data => data.canopies));
    }

    getAllBySizeByModel(): Observable<Array<CanopyModelBySize>> {
        return this.apiService.get(`${this._apiVersion}/canopies/allBySizeByModel`)
            .pipe(map(data => data.canopies));
    }

    getAllBySizeByModelByYear(): Observable<Array<CanopyModelByYear>> {
        return this.apiService.get(`${this._apiVersion}/canopies/allBySizeByModelByYear`)
            .pipe(map(data => data.canopies));
    }

}