import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '@environments/environment';
import { Observable } from 'rxjs';

@Injectable({ providedIn: 'root' })
export class WebhookRetryService {
  private http = inject(HttpClient);
  private apiUrl = `${environment.localServiceTestApiUrl}/webhooks`;

  retryWebhook(webhookId: string): Observable<{ success: boolean }> {
    return this.http.post<{ success: boolean }>(
      `${this.apiUrl}/${webhookId}/retry`,
      {}
    );
  }

  bulkRetryWebhooks(webhookIds: string[]): Observable<{ success: number; failed: number }> {
    return this.http.post<{ success: number; failed: number }>(
      `${this.apiUrl}/bulk-retry`,
      { webhookIds }
    );
  }

  getRetryConfig(): Observable<any> {
    return this.http.get(`${this.apiUrl}/retry-config`);
  }

  updateRetryConfig(config: any): Observable<any> {
    return this.http.put(`${this.apiUrl}/retry-config`, config);
  }
}