import { Injectable } from '@angular/core';
import { State, Selector, Action, StateContext } from '@ngxs/store';
import { Notify } from '../actions/notifier.actions';

export class NotifierStateModel {
  processId: number;
}

@State<NotifierStateModel>({
  name: 'notifier',
  defaults: {
    processId: null,
  },
})
@Injectable()
export class NotifierState {
  @Selector()
  static getNotifier(state: NotifierStateModel) {
    return state.processId;
  }

  @Action(Notify)
  notify(ctx: StateContext<NotifierStateModel>, { payload }: Notify) {
    const state = ctx.getState();
    ctx.patchState({
      ...state,
      processId: payload,
    });
  }
}
