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);

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

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

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

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