import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { ITrnmst, IDropBdg } from '../../interfaces/main.interface';

@Injectable({
  providedIn: 'root'
})
export class TransactionStateService {
  // ประกาศ BehaviorSubject ด้วย Interface
  private transactionState = new BehaviorSubject<ITrnmst[] | null>(null);
  private budgetState = new BehaviorSubject<IDropBdg[] | null>(null);

  // ส่ง Observable ไปให้ components subscribe
  getTransactionState(): Observable<ITrnmst[] | null> {
    return this.transactionState.asObservable();
  }

  // เซ็ท state
  setTransactionState(transactions: ITrnmst[]): void {
    this.transactionState.next(transactions);
  }

  // เคลียร์ state
  clearState(): void {
    this.transactionState.next(null);
  }


  setBudgetDrop(budget: IDropBdg[]): void {
    this.budgetState.next(budget);
  }

  getBudgetDrop(): Observable<IDropBdg[] | null> {
    return this.budgetState.asObservable();
  }
}
