import { gql, useQuery } from '@apollo/client';
import { DecisionSupportFile } from '../../types/decision';
import { useGraphQLData } from './helper';

export const QUERY_DECISION_SUPPORT_FILES = gql`
  query decisionSupportFiles($filter: DecisionSupportFileFilter) {
    decisionSupportFiles(filter: $filter) {
      id,
      title,
      sections,
      createdAt,
      closedAt,
      votedAt,
      status,
      workgroup {
        id,
        name,
        members {
          id,
          email,
          name
        }
      },
    }
  }
`;

export function useDecisionSupportFilesQuery(options = {}) {
  return useQuery(QUERY_DECISION_SUPPORT_FILES, options);
}

export function useDecisionSupportFiles(options = {}) {
  const { data, loading, error } = useGraphQLData<DecisionSupportFile[]>(
    QUERY_DECISION_SUPPORT_FILES, 'decisionSupportFiles', [], options
  );
  return { decisionSupportFiles: data, loading, error };
}