import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from '../../../environments/environment';
import { ApiResponse } from '../models/api.model';
import { SupportLabel, CreateSupportLabel } from '../models/support-label.model';

@Injectable({ providedIn: 'root' })
export class SupportLabelService {
  private http = inject(HttpClient);
  private baseUrl = `${environment.apiUrl}/support/labels`;

  list(): Observable<{ data: SupportLabel[] }> {
    return this.http.get<{ data: SupportLabel[] }>(this.baseUrl);
  }

  create(data: CreateSupportLabel): Observable<ApiResponse<SupportLabel>> {
    return this.http.post<ApiResponse<SupportLabel>>(this.baseUrl, data);
  }

  update(id: number, data: Partial<CreateSupportLabel>): Observable<ApiResponse<SupportLabel>> {
    return this.http.put<ApiResponse<SupportLabel>>(`${this.baseUrl}/${id}`, data);
  }

  getById(id: number): Observable<ApiResponse<SupportLabel>> {
    return this.http.get<ApiResponse<SupportLabel>>(`${this.baseUrl}/${id}`);
  }

  delete(id: number): Observable<any> {
    return this.http.delete(`${this.baseUrl}/${id}`);
  }
}
