import gql from "graphql-tag";

export const GET_DOC_SIZE_TOTALS = gql`
  query GET_DOC_SIZE_TOTALS($jobId: uuid!) {
    documents_aggregate(where: { jobid: { _eq: $jobId } }) {
      aggregate {
        sum {
          size
        }
      }
    }
  }
`;

export const GET_DOCUMENTS_BY_JOB = gql`
  query GET_DOCUMENTS_BY_JOB($jobId: uuid!) {
    documents_aggregate(where: { jobid: { _eq: $jobId } }) {
      aggregate {
        sum {
          size
        }
      }
    }
    documents(order_by: { takenat: desc }) {
      id
      name
      key
      type
      takenat
      extension
      jobid
    }
  }
`;

export const INSERT_NEW_DOCUMENT = gql`
  mutation INSERT_NEW_DOCUMENT($docInput: [documents_insert_input!]!) {
    insert_documents(objects: $docInput) {
      returning {
        id
        name
        key
        type
        takenat
        extension
        jobid
      }
    }
  }
`;

export const DELETE_DOCUMENT = gql`
  mutation DELETE_DOCUMENT($id: uuid) {
    delete_documents(where: { id: { _eq: $id } }) {
      returning {
        id
      }
    }
  }
`;
