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

export const QUERY_ALL_TT_APPROVALS_PAGINATED = gql`
  query QUERY_ALL_TT_APPROVALS_PAGINATED($offset: Int, $limit: Int, $order: [tt_approval_queue_order_by!]!) {
    tt_approval_queue(offset: $offset, limit: $limit, order_by: $order, where: { approved_at: { _is_null: true } }) {
      id
      jobid
      bodyshopid
      employeeid
      employee {
        first_name
        last_name
        id
      }
      job {
        ro_number
        status
        id
      }
      employeeid
      actualhrs
      productivehrs
      ciecacode
      cost_center
      date
      memo
      flat_rate
      clockon
      clockoff
      rate
      created_by
      task_name
      payout_context
    }
    tt_approval_queue_aggregate {
      aggregate {
        count(distinct: true)
      }
    }
  }
`;

export const INSERT_NEW_TT_APPROVALS = gql`
  mutation INSERT_NEW_TT_APPROVALS($timeTicketInput: [tt_approval_queue_insert_input!]!) {
    insert_tt_approval_queue(objects: $timeTicketInput) {
      returning {
        id
        employeeid
        productivehrs
        actualhrs
        ciecacode
        cost_center
        date
        memo
        flat_rate
        rate
        clockon
        clockoff
        created_by
        task_name
        payout_context
      }
    }
  }
`;

export const QUERY_TT_APPROVALS_BY_IDS = gql`
  query QUERY_TT_APPROVALS_BY_IDS($ids: [uuid!]!) {
    tt_approval_queue(where: { id: { _in: $ids } }) {
      id
      productivehrs
      actualhrs
      rate
      memo
      jobid
      flat_rate
      employeeid
      date
      ciecacode
      bodyshopid
      cost_center
      clockon
      clockoff
      created_by
      task_name
      payout_context
    }
  }
`;

export const UPDATE_TT_BY_APPROVAL = gql`
  mutation UPDATE_TT_BY_APPROVAL($ttApprovalUpdates: [tt_approval_queue_updates!]!) {
    update_tt_approval_queue_many(updates: $ttApprovalUpdates) {
      returning {
        id
        approved_at
        approved_by
        timeticket {
          id
        }
      }
    }
  }
`;
