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

export const GET_PHONE_NUMBER_OPT_OUT = gql`
  query GET_PHONE_NUMBER_OPT_OUT($bodyshopid: uuid!, $phone_number: String!) {
    phone_number_opt_out(where: { bodyshopid: { _eq: $bodyshopid }, phone_number: { _eq: $phone_number } }) {
      id
      bodyshopid
      phone_number
      created_at
      updated_at
    }
  }
`;

export const GET_PHONE_NUMBER_OPT_OUTS = gql`
  query GET_PHONE_NUMBER_OPT_OUTS($bodyshopid: uuid!, $search: String) {
    phone_number_opt_out(
      where: { bodyshopid: { _eq: $bodyshopid }, phone_number: { _ilike: $search } }
      order_by: [{ phone_number: asc }, { updated_at: desc }]
    ) {
      id
      bodyshopid
      phone_number
      created_at
      updated_at
    }
  }
`;

export const GET_PHONE_NUMBER_OPT_OUTS_BY_NUMBERS = gql`
  query GET_PHONE_NUMBER_OPT_OUTS_BY_NUMBERS($bodyshopid: uuid!, $phone_numbers: [String!]) {
    phone_number_opt_out(
      where: { bodyshopid: { _eq: $bodyshopid }, phone_number: { _in: $phone_numbers } }
    ) {
      id
      bodyshopid
      phone_number
      created_at
      updated_at
    }
  }
`;

export const SEARCH_OWNERS_BY_PHONE_NUMBERS = gql`
  query SEARCH_OWNERS_BY_PHONE_NUMBERS($bodyshopid: uuid!, $phone_numbers: [String!]) {
    owners(
      where: {
        shopid: { _eq: $bodyshopid },
        _or: [
          { ownr_ph1: { _in: $phone_numbers } },
          { ownr_ph2: { _in: $phone_numbers } }
        ]
      }
    ) {
      id
      ownr_fn
      ownr_ln
      ownr_co_nm
      ownr_ph1
      ownr_ph2
      __typename
    }
  }
`;
