import { gql } from "apollo-boost";

export const QUERY_VENDOR_BY_ID = gql`
  query QUERY_VENDOR_BY_ID($id: uuid!) {
    vendors_by_pk(id: $id) {
      zip
      terms
      taxid
      street2
      state
      prompt_discount
      name
      id
      favorite
      email
      due_date
      display_name
      discount
      country
      cost_center
      city
      street1
    }
  }
`;

export const UPDATE_VENDOR = gql`
  mutation UPDATE_VENDOR($id: uuid!, $vendor: vendors_set_input!) {
    update_vendors(where: { id: { _eq: $id } }, _set: $vendor) {
      returning {
        id
      }
    }
  }
`;

export const QUERY_ALL_VENDORS = gql`
  query QUERY_ALL_VENDORS {
    vendors {
      name
      id
      street1
      cost_center
      city
    }
  }
`;

export const INSERT_NEW_VENDOR = gql`
  mutation INSERT_NEW_VENDOR($vendorInput: [vendors_insert_input!]!) {
    insert_vendors(objects: $vendorInput) {
      returning {
        id
      }
    }
  }
`;

export const DELETE_VENDOR = gql`
  mutation DELETE_VENDOR($id: uuid!) {
    delete_vendors(where: { id: { _eq: $id } }) {
      returning {
        id
      }
    }
  }
`;

export const QUERY_ALL_VENDORS_FOR_ORDER = gql`
  query QUERY_ALL_VENDORS_FOR_ORDER {
    vendors(order_by: { favorite: desc }) {
      name
      cost_center
      id
      favorite
    }
  }
`;

export const SEARCH_VENDOR_AUTOCOMPLETE = gql`
  query SEARCH_VENDOR_AUTOCOMPLETE {
    vendors {
      name
      discount
      id
      cost_center
    }
  }
`;
