// import { Injectable, signal } from '@angular/core';
// import { Observable, of } from 'rxjs';
// import { CourseReportDetail, CourseReportDetailRow, CourseReportSummary } from '../interfaces/report';
// import { REPORT_SUMMARIES_MOCK, REPORT_DETAILS_MOCK } from '../mocks/report.mocks';
// import { normalizePage } from '@shared/paging/normalize-page';
// import { ListParams, PagedResult, SortDir } from '@shared/paging/paging';

// @Injectable({ providedIn: 'root' })
// export class ReportService {
//   private summaries = signal<CourseReportSummary[]>([...REPORT_SUMMARIES_MOCK]);

//   list(params: ListParams): Observable<PagedResult<CourseReportSummary>> {
//     let data = [...this.summaries()];
//     const q = (params.search ?? '').toLowerCase();
//     if (q) {
//       data = data.filter((r) =>
//         [
//           r.course.nom,
//           r.course.type,
//           r.course.reunion?.hippodrome?.nom,
//           String(r.course.numero),
//         ]
//           .filter(Boolean)
//           .map((s) => String(s).toLowerCase())
//           .some((s) => s.includes(q))
//       );
//     }
//     if (params.sortKey && params.sortDir) {
//       const { sortKey, sortDir } = params as { sortKey: string; sortDir: SortDir };
//       const get = (o: any, k: string) => k.split('.').reduce((a, b) => a?.[b], o);
//       data = [...data].sort((a, b) => String(get(a, sortKey) ?? '').localeCompare(String(get(b, sortKey) ?? ''), 'fr', { numeric: true }) * (sortDir === 'asc' ? 1 : -1));
//     }
//     const start = (params.page - 1) * params.perPage;
//     const pageData = data.slice(start, start + params.perPage);
//     return of(normalizePage<CourseReportSummary>({ data: pageData, meta: { total: data.length } }, params.page, params.perPage));
//   }

//   getDetail(courseId: string): Observable<CourseReportDetail | undefined> {
//     const summary = this.summaries().find((s) => s.id === courseId);
//     if (!summary) return of(undefined);
//     const rows = REPORT_DETAILS_MOCK.get(courseId) ?? [];
//     return of({ summary, rows });
//   }

//   // === Actions ===
//   validate(courseId: string): Observable<CourseReportSummary | undefined> {
//     let updated: CourseReportSummary | undefined;
//     this.summaries.set(
//       this.summaries().map((s) => (s.id === courseId ? ((updated = { ...s, statut: 'Validé', confirmed: false }), updated) : s))
//     );
//     return of(updated);
//   }

//   confirm(courseId: string): Observable<CourseReportSummary | undefined> {
//     let updated: CourseReportSummary | undefined;
//     this.summaries.set(
//       this.summaries().map((s) => (s.id === courseId ? ((updated = { ...s, statut: 'Validé', confirmed: true }), updated) : s))
//     );
//     return of(updated);
//   }

//   resetStatus(courseId: string): Observable<CourseReportSummary | undefined> {
//     let updated: CourseReportSummary | undefined;
//     this.summaries.set(
//       this.summaries().map((s) => (s.id === courseId ? ((updated = { ...s, statut: 'Non Validé', confirmed: false }), updated) : s))
//     );
//     return of(updated);
//   }

//   modifyRows(courseId: string, rows: CourseReportDetailRow[]): Observable<boolean> {
//     REPORT_DETAILS_MOCK.set(courseId, rows);
//     return of(true);
//   }
// }


