import { gql, useQuery, useMutation } from '@apollo/client';
import { QUERY_DECISION_SUPPORT_FILES } from '../queries/dsf';

export const MUTATION_CREATE_DECISION_SUPPORT_FILE = gql`
mutation createDecisionSupportFile($changes: DecisionSupportFileChanges!) {
  createDecisionSupportFile(changes: $changes) {
    id,
    title,
    status,
    sections,
    createdAt,
    updatedAt,
    workgroup {
      id,
      name,
      members {
        id,
        email,
        name
      }
    },
  }
}`;

export function useCreateDecisionSupportFileMutation() {
  return useMutation(MUTATION_CREATE_DECISION_SUPPORT_FILE, {
    refetchQueries: [{query: QUERY_DECISION_SUPPORT_FILES}],
  });
}

export const MUTATION_UPDATE_DECISION_SUPPORT_FILE = gql`
mutation updateDecisionSupportFile($id: ID!, $changes: DecisionSupportFileChanges!) {
  updateDecisionSupportFile(id: $id, changes: $changes) {
    id,
    title,
    status,
    sections,
    createdAt,
    updatedAt,
    workgroup {
      id,
      name,
      members {
        id,
        email,
        name
      }
    },
  }
}`;

export function useUpdateDecisionSupportFileMutation() {
  return useMutation(MUTATION_UPDATE_DECISION_SUPPORT_FILE, {
    refetchQueries: [{
      query: QUERY_DECISION_SUPPORT_FILES,
    }],
  });
}