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

export const INSERT_PARTS_DISPATCH = gql`
  mutation INSERT_PARTS_DISPATCH($partsDispatch: parts_dispatch_insert_input!) {
    insert_parts_dispatch_one(object: $partsDispatch) {
      id
      jobid
      number
      employeeid
      parts_dispatch_lines {
        id
        joblineid
        quantity
      }
    }
  }
`;

export const GET_UNACCEPTED_PARTS_DISPATCH = gql`
  query GET_UNACCEPTED_PARTS_DISPATCH($techId: uuid!, $offset: Int, $limit: Int) {
    parts_dispatch_aggregate(
      where: { employeeid: { _eq: $techId }, parts_dispatch_lines: { accepted_at: { _is_null: true } } }
    ) {
      aggregate {
        count(distinct: true)
      }
    }
    parts_dispatch(
      offset: $offset
      limit: $limit
      where: { employeeid: { _eq: $techId }, parts_dispatch_lines: { accepted_at: { _is_null: true } } }
    ) {
      id
      job {
        id
        ro_number
        status
        v_make_desc
        v_model_desc
        v_model_yr
        v_color
      }
      dispatched_at
      dispatched_by
      parts_dispatch_lines {
        id
        accepted_at
        jobline {
          line_desc
          id
        }
        quantity
        joblineid
      }
    }
  }
`;

export const UPDATE_PARTS_DISPATCH_LINE = gql`
  mutation UPDATE_PARTS_DISPATCH_LINE($id: uuid!, $line: parts_dispatch_lines_set_input!) {
    update_parts_dispatch_lines_by_pk(pk_columns: { id: $id }, _set: $line) {
      accepted_at
      id
    }
  }
`;
