import { Injectable, inject } 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 apiService = inject(ApiService);

    private _apiDomain = '/skydive';

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

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

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

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