import { gql } from "apollo-boost";

export const QUERY_SEARCH_OWNER_BY_IDX = gql`
  query QUERY_SEARCH_OWNER_BY_IDX($search: String!) {
    search_owner(args: { search: $search }) {
      ownr_fn
      ownr_ln
      ownr_ph1
      ownr_ph2
      ownr_addr1
      ownr_addr2
      ownr_city
      ownr_ctry
      ownr_ea
      ownr_st
      ownr_zip
      id
    }
  }
`;

export const QUERY_OWNER_BY_ID = gql`
  query QUERY_OWNER_BY_ID($id: uuid!) {
    owners_by_pk(id: $id) {
      id
      allow_text_message
      ownr_addr1
      ownr_addr2
      ownr_co_nm
      ownr_city
      ownr_ctry
      ownr_ea
      ownr_fn
      ownr_ph1
      ownr_ln
      ownr_ph2
      ownr_st
      ownr_title
      ownr_zip
      preferred_contact
      jobs {
        id
        ro_number
        est_number
        clm_no
        status
        clm_total
        vehicle {
          id
          v_model_yr
          v_model_desc
          v_make_desc
        }
      }
    }
  }
`;

export const UPDATE_OWNER = gql`
  mutation UPDATE_OWNER($ownerId: uuid!, $owner: owners_set_input!) {
    update_owners(where: { id: { _eq: $ownerId } }, _set: $owner) {
      returning {
        id
      }
    }
  }
`;

export const QUERY_ALL_OWNERS = gql`
  query QUERY_ALL_OWNERS {
    owners {
      id
      allow_text_message
      created_at
      ownr_addr1
      ownr_addr2
      ownr_co_nm
      ownr_city
      ownr_ctry
      ownr_ea
      ownr_fn
      ownr_ph1
      ownr_ln
      ownr_ph2
      ownr_st
      ownr_title
      ownr_zip
      preferred_contact
      updated_at
    }
  }
`;
