import { inject, Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { environment } from '../../environments/environment'; export interface IntervalData { timestamp: string; consumptionKwh: number; communityFeedInKwh: number; coveredKwh: number; coveragePercent: number; } export interface Summary { totalConsumptionKwh: number; totalCoveredKwh: number; totalCommunityFeedInKwh: number; averageCoveragePercent: number; } export interface ConsumptionDashboardResponse { meteringPointId: string; atNumber: string; energyCommunityId: string | null; communityName: string | null; from: string; to: string; granularity: 'DAILY' | 'HOURLY'; data: IntervalData[]; summary: Summary; } @Injectable({ providedIn: 'root' }) export class ConsumptionService { private http = inject(HttpClient); private apiUrl = `${environment.apiUrl}/api/community/consumption`; getDashboard( meteringPointId: string, from: string, to: string ): Observable { const params = new HttpParams() .set('from', from) .set('to', to); return this.http.get( `${this.apiUrl}/${meteringPointId}/dashboard`, { params } ); } }