import { gql } from "apollo-boost";

export const GET_JOB_LINES_BY_PK = gql`
  query GET_JOB_LINES_BY_PK($id: uuid!) {
    joblines(where: { jobid: { _eq: $id } }, order_by: { unq_seq: asc }) {
      id
      unq_seq
      line_ind
      line_desc
      part_type
      oem_partno
      db_price
      act_price
      part_qty
      mod_lbr_ty
      db_hrs
      mod_lb_hrs
      lbr_op
      lbr_amt
      op_code_desc
      status
      parts_order_lines {
        id
        parts_order {
          id
          order_number
          order_date
          user_email
          vendor {
            id
            name
          }
        }
      }
      allocations {
        id
        hours
        employee {
          id
          first_name
          last_name
        }
      }
    }
  }
`;

export const UPDATE_JOB_LINE_STATUS = gql`
  mutation UPDATE_JOB_LINE_STATUS($ids: [uuid!]!, $status: String!) {
    update_joblines(where: { id: { _in: $ids } }, _set: { status: $status }) {
      affected_rows
    }
  }
`;
export const INSERT_NEW_JOB_LINE = gql`
  mutation INSERT_NEW_JOB_LINE($lineInput: [joblines_insert_input!]!) {
    insert_joblines(objects: $lineInput) {
      returning {
        id
      }
    }
  }
`;

export const UPDATE_JOB_LINE = gql`
  mutation UPDATE_JOB_LINE($lineId: uuid!, $line: joblines_set_input!) {
    update_joblines(where: { id: { _eq: $lineId } }, _set: $line) {
      returning {
        id
      }
    }
  }
`;

export const GET_JOB_LINES_TO_ENTER_INVOICE = gql`
  query GET_JOB_LINES_TO_ENTER_INVOICE($id: uuid!) {
    joblines(
      where: {
        jobid: { _eq: $id }
        oem_partno: { _neq: "" }
        act_price: { _gt: "0" }
      }
    ) {
      id
      line_desc
      part_type
      oem_partno
      db_price
      act_price
      part_qty
      mod_lbr_ty
      db_hrs
      mod_lb_hrs
      lbr_op
      lbr_amt
      op_code_desc
    }
  }
`;
