/* eslint-disable import/prefer-default-export */
import type { ApolloClient } from '@apollo/client';
import { gql } from '@apollo/client';

import type { User } from 'api/user/types';
import type { GetOwnerDataQuery, GetOwnerDataQueryVariables } from 'gql/crm.types';

const QUERY_GET_OWNER_DATA = gql`
  query GetOwnerData($domainname: String) {
    selectLead: leads(owner_domainname: $domainname) {
      label: fullname
      value: leadid
    }
    selectOpportunity: opportunities(owner_domainname: $domainname) {
      label: name
      value: opportunityid
    }
  }
`;

export async function getOwnerData({ query }: ApolloClient<object>, user: User) {
  return query<GetOwnerDataQuery, GetOwnerDataQueryVariables>({
    query: QUERY_GET_OWNER_DATA,
    variables: {
      domainname: user?.domainName,
    },
  });
}
