// Questo file fa parte di MyTown.
// MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
// i termini della GNU Affero General Public License come pubblicata dalla
// Free Software Foundation, versione 3.
// Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
// Copyright (C) Kondor Consulting & Services S.r.l.
// SPDX-License-Identifier: AGPL-3.0-or-later

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

import { ConfigService } from './config.service';
import { ServiceCategory } from 'src/models/biz-appointments/service-category.model';

@Injectable({
	providedIn: 'root',
})
export class BizServiceCategoriesService {
	constructor(
		private http: HttpClient,
		private configService: ConfigService,
	) {}

	private get baseUrl(): string {
		return this.configService.serviceUrl_BizAppointments;
	}

	getServiceCategories(cmp_id: number): Observable<ServiceCategory[]> {
		return this.http.get(`${this.baseUrl}categories/list?cmp_id=${cmp_id}`, { observe: 'response' }).pipe(map((response: any) => response.body));
	}

	insertServiceCategory(category: Partial<ServiceCategory>): Observable<number> {
		return this.http.post(`${this.baseUrl}categories/add`, category, { observe: 'response' }).pipe(map((response: any) => response.body));
	}
}
