import { gql } from "apollo-boost";

export const QUERY_ALL_ACTIVE_APPOINTMENTS = gql`
  query QUERY_ALL_ACTIVE_APPOINTMENTS {
    appointments(where: { canceled: { _eq: false } }) {
      start
      id
      end
      title
      isintake
      job {
        ro_number
        ownr_ln
        ownr_fn
        ownr_ph1
        ownr_ea
        clm_total
        id
        clm_no
        vehicle {
          id
          v_model_yr
          v_make_desc
          v_model_desc
        }
      }
    }
  }
`;

export const INSERT_APPOINTMENT = gql`
  mutation INSERT_APPOINTMENT($app: [appointments_insert_input!]!) {
    insert_appointments(objects: $app) {
      returning {
        id
      }
    }
  }
`;

export const QUERY_APPOINTMENT_BY_DATE = gql`
  query QUERY_APPOINTMENT_BY_DATE($start: timestamptz, $end: timestamptz) {
    appointments(
      where: { start: { _lte: $end, _gte: $start }, canceled: { _eq: false } }
    ) {
      start
      id
      end
      title
      isintake
      job {
        ro_number
        ownr_ln
        ownr_fn
        ownr_ph1
        ownr_ea
        clm_total
        id
        clm_no
        vehicle {
          id
          v_model_yr
          v_make_desc
          v_model_desc
        }
      }
    }
  }
`;

export const CANCEL_APPOINTMENT_BY_ID = gql`
  mutation CANCEL_APPOINTMENT_BY_ID($appid: uuid!) {
    update_appointments(
      where: { id: { _eq: $appid } }
      _set: { canceled: true }
    ) {
      returning {
        id
      }
    }
  }
`;

export const QUERY_APPOINTMENTS_BY_JOBID = gql`
  query QUERY_APPOINTMENTS_BY_JOBID($jobid: uuid!) {
    appointments(where: { jobid: { _eq: $jobid } }) {
      start
      id
      end
      isintake
      arrived
      canceled
      created_at
    }
  }
`;
