// angular
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

// libs
import { Observable } from 'rxjs';

// app
import { ApiRoutes } from '../api-routes';
import { ItemModel } from '../model/item.model';
import { ItemCategoryModel } from '../model/item.category.model';

@Injectable()
export class ItemService {

	constructor(
		private httpClient: HttpClient,
	) {
	}

	public getCategories(category?: string): Observable<ItemCategoryModel[]> {
		return this.httpClient
			.get<ItemCategoryModel[]>(ApiRoutes.SettingsItemCategories);
	}

	public getItems(categoryId?: string): Observable<ItemModel[]> {
		var url = categoryId
			? ApiRoutes.SettingsItems + "?category=" + categoryId
			: ApiRoutes.SettingsItems;

		return this.httpClient
			.get<ItemCategoryModel[]>(url);
	}
}
