import { Container } from 'inversify';

<% if (apollo) { %>

import { ApolloClient, InMemoryCache } from '@apollo/client';
import type { ApolloClientType } from '@brainly-gene/apollo';
import { apolloFactory } from '@brainly-gene/apollo';

<% } %>

<% if (reactQuery) { %>

import type { ReactQueryClientType } from '@brainly-gene/core';
import { reactQueryFactory } from '@brainly-gene/core';
import { QueryClient } from '@tanstack/react-query';

<% } %>


export function getBaseContainer() {
  const container = new Container();
<% if (!apollo && reactQuery) { %>
  const reactQueryContainer = new Container();

  /* Configure your RQ client */
  const rqClient = new QueryClient();

  reactQueryContainer
    .bind<ReactQueryClientType>('reactQueryClient')
    .toConstantValue(reactQueryFactory(() => rqClient));
<% } %>
<% if (apollo && !reactQuery) { %>
  const apolloContainer = new Container();

  /* Configure your apollo client */
  const apolloClient = new ApolloClient({
    cache: new InMemoryCache(),
  });
  apolloContainer
    .bind<ApolloClientType>('apolloClient')
    .toConstantValue(apolloFactory(() => apolloClient));
<% } %>
<% if (apollo && reactQuery) { %>
    const reactQueryContainer = new Container();

  /* Configure your RQ client */
  const rqClient = new QueryClient();

  reactQueryContainer
    .bind<ReactQueryClientType>('reactQueryClient')
    .toConstantValue(reactQueryFactory(() => rqClient));

  const apolloContainer = new Container();
  /* Configure your apollo client */
  const apolloClient = new ApolloClient({
    cache: new InMemoryCache(),
  });
  apolloContainer
    .bind<ApolloClientType>('apolloClient')
    .toConstantValue(apolloFactory(() => apolloClient));
<% } %>

  return Container.merge(
    container,
  <% if (apollo && !reactQuery) { %>
    apolloContainer,
  <% } %>
  <% if (!apollo && reactQuery) { %>
    reactQueryContainer,
  <% } %>
  <% if (apollo && reactQuery) { %>
    apolloContainer,
    reactQueryContainer,
  <% } %>
  ) as Container;
}
