// 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 { ServiceType } from 'src/models/biz-appointments/service-type.model';

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

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

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

	getServiceType(id: number): Observable<ServiceType> {
		return this.http
			.get(`${this.baseUrl}service-types/get/${id}`, { observe: 'response' })
			.pipe(map((response: any) => response.body));
	}

	insertServiceType(serviceType: Partial<ServiceType>): Observable<number> {
		return this.http
			.post(`${this.baseUrl}service-types/add`, serviceType, { observe: 'response' })
			.pipe(map((response: any) => response.body));
	}

	updateServiceType(serviceType: ServiceType): Observable<number> {
		return this.http
			.put(`${this.baseUrl}service-types/upd`, serviceType, { observe: 'response' })
			.pipe(map((response: any) => response.body));
	}

	deleteServiceType(id: number): Observable<number> {
		return this.http
			.delete(`${this.baseUrl}service-types/del/${id}`, { observe: 'response' })
			.pipe(map((response: any) => response.body));
	}
}
