import { gql } from "@apollo/client";

export const INSERT_PAYMENT_RESPONSE = gql`
  mutation INSERT_PAYMENT_RESPONSE($paymentResponse: [payment_response_insert_input!]!) {
    insert_payment_response(objects: $paymentResponse) {
      returning {
        id
      }
    }
  }
`;

export const QUERY_PAYMENT_RESPONSE_BY_PAYMENT_ID = gql`
  query QUERY_PAYMENT_RESPONSE_BY_PK($paymentid: uuid!) {
    payment_response(where: { paymentid: { _eq: $paymentid } }) {
      id
      jobid
      bodyshopid
      paymentid
      amount
      declinereason
      ext_paymentid
      successful
      response
    }
  }
`;

export const QUERY_RO_AND_OWNER_BY_JOB_PKS = gql`
  query QUERY_RO_AND_OWNER_BY_JOB_PKS($jobids: [uuid!]!) {
    jobs(where: { id: { _in: $jobids } }) {
      ro_number
      ownr_fn
      ownr_ln
      ownr_ea
      ownr_zip
    }
  }
`;

export const GET_REFUNDABLE_AMOUNT_BY_JOBID = gql`
  query GET_REFUNDABLE_AMOUNT_BY_JOBID($jobid: uuid!) {
    payment_response_aggregate(where: { jobid: { _eq: $jobid } }) {
      aggregate {
        sum {
          amount
        }
      }
    }
  }
`;
