import { atom } from 'jotai';
import {
  OrgAnalyticsAmplitudeConfig,
  OrgAnalyticsConfig,
  OrgAnalyticsCustomerServiceConfig,
  OrgAnalyticsGoogleAnalyticsConfig,
} from 'src/application/models/api/orgAnalyticsConfig';

const internalOrgAnalyticsConfigAtom = atom<OrgAnalyticsConfig | undefined>(undefined);

export const orgAnalyticsConfigAtom = atom(
  get => get(internalOrgAnalyticsConfigAtom),
  (_, set, value: OrgAnalyticsConfig) => {
    set(internalOrgAnalyticsConfigAtom, value);
  },
);

export const orgAnalyticsAmplitudeConfigAtom = atom<OrgAnalyticsAmplitudeConfig | undefined>(
  get => get(orgAnalyticsConfigAtom)?.amplitude,
);

export const orgAnalyticsCustomerServiceConfigAtom = atom<
  OrgAnalyticsCustomerServiceConfig | undefined
>(get => get(orgAnalyticsConfigAtom)?.customerService);

export const orgAnalyticsGoogleAnalyticsConfigAtom = atom<
  OrgAnalyticsGoogleAnalyticsConfig | undefined
>(get => get(orgAnalyticsConfigAtom)?.googleAnalytics);
