import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { MaterialCode, MaterialSetting } from '../models/recipe.model'; import { environment } from 'src/environments/environment'; import { Observable } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class MaterialService { constructor(private _httpClient: HttpClient) {} getMaterialCodes( matIds?: number[], country?: string, filename?: string ): Observable { return this._httpClient.get( `${environment.api}/materials/code`, { params: { country: country || this.getCurrentCountry(), filename: filename || this.getCurrentFile(), mat_ids: matIds?.join(',') || '', }, withCredentials: true, } ); } getMaterialSettingById( id: number, country?: string, filename?: string ): Observable { return this._httpClient.get( `${environment.api}/materials/setting/${id}`, { params: { country: country || this.getCurrentCountry(), filename: filename || this.getCurrentFile(), }, withCredentials: true, } ); } getCurrentFile(): string { const currentRecipeFile = localStorage.getItem('currentRecipeFile'); if (currentRecipeFile) { return currentRecipeFile; } return 'coffeethai02_580.json'; } getCurrentCountry(): string { const currentRecipeCountry = localStorage.getItem('currentRecipeCountry'); if (currentRecipeCountry) { return currentRecipeCountry; } return 'Thailand'; } }