/**
 * @copyright NHCarrigan
 * @license Naomi's Public License
 * @author Naomi Carrigan
 */
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import type {
  CommentReportWithDetails,
  CreateCommentReportDto,
  UpdateCommentReportDto,
  ReportStatus,
} from '@library/shared-types';
import { environment } from '../../environments/environment';

@Injectable({
  providedIn: 'root',
})
export class CommentReportService {
  private readonly http = inject(HttpClient);
  private readonly apiUrl = `${environment.apiUrl}/comment-reports`;

  createReport(
    dto: CreateCommentReportDto,
  ): Observable<CommentReportWithDetails> {
    return this.http.post<CommentReportWithDetails>(this.apiUrl, dto);
  }

  getAllReports(
    status?: ReportStatus,
  ): Observable<CommentReportWithDetails[]> {
    const params: Record<string, string> = {};
    if (status) {
      params['status'] = status;
    }
    return this.http.get<CommentReportWithDetails[]>(this.apiUrl, { params });
  }

  getReportById(id: string): Observable<CommentReportWithDetails> {
    return this.http.get<CommentReportWithDetails>(`${this.apiUrl}/${id}`);
  }

  updateReport(
    id: string,
    dto: UpdateCommentReportDto,
  ): Observable<CommentReportWithDetails> {
    return this.http.put<CommentReportWithDetails>(`${this.apiUrl}/${id}`, dto);
  }
}
