import { createSelector } from '@ngrx/store';
import { selectBranchState } from '../branch.selectors';
import { taskArticlesAdapter } from './task-articles.state';
import { ArticleDTO } from './defs';

export const selectTaskArticlesState = createSelector(selectBranchState, (s) => s.taskArticles);

const { selectAll } = taskArticlesAdapter.getSelectors(selectTaskArticlesState);

export const selectArticlesByTaskId = createSelector(selectAll, (s: ArticleDTO[], taskId: number) =>
  s.filter((article) => article.taskId === taskId)
);
