import { Injectable, inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; export interface EnergyPrice { SEK_per_kWh: number; EUR_per_kWh: number; EXR: number; time_start: string; time_end: string; } @Injectable({ providedIn: 'root' }) export class EnergyPriceService { private apiBaseUrl = 'https://www.elprisetjustnu.se/api/v1/prices'; private http = inject(HttpClient); getPrices(year: string, month: string, day: string, priceClass: string): Observable { const url = `${this.apiBaseUrl}/${year}/${month}-${day}_${priceClass}.json`; return this.http.get(url); } formatDate(date: Date): { year: string, month: string, day: string } { const year = date.getFullYear().toString(); const month = (date.getMonth() + 1).toString().padStart(2, '0'); const day = date.getDate().toString().padStart(2, '0'); return { year, month, day }; } }