import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';

@Injectable({
  providedIn: 'root',
})
export class SharedService {
  // Use BehaviorSubject to hold the values
  private transactionIdSource = new BehaviorSubject<string>('');
  private serverPathSource = new BehaviorSubject<string>('');
  private jobidSource = new BehaviorSubject<string>('');
  private filenameSource = new BehaviorSubject<string>('');
  private tokenSource = new BehaviorSubject<string>('');
  private projectdefinitionIdSource = new BehaviorSubject<string>('');

  // Observable streams to access the values in components
  transactionId$ = this.transactionIdSource.asObservable();
  serverPath$ = this.serverPathSource.asObservable();
  jobid$ = this.jobidSource.asObservable();
  filename$ = this.filenameSource.asObservable();  
  token$ = this.tokenSource.asObservable();
  projectdefinitionId$ = this.projectdefinitionIdSource.asObservable();

  // Methods to update the values
  setTransactionId(transactionId: string) {
    this.transactionIdSource.next(transactionId);
  }

  setServerPath(serverPath: string) {
    this.serverPathSource.next(serverPath);
  }
  
  setJobId(jobid: string) {
    this.jobidSource.next(jobid);
  }

  setToken(token: string) {
    this.tokenSource.next(token);
  }

  setFileName(filename: string) {
    this.filenameSource.next(filename);
  }  

  setProjectDefinitionId(projectdefinitionid : string){
    this.projectdefinitionIdSource.next(projectdefinitionid);
  }

}
