import apiClient from '../../../shared/services/apiClient';

export type CookieCategoryPreferences = {
  necessary: boolean;
  analytics: boolean;
  marketing: boolean;
  preferences: boolean;
};

export type CookieConsent = {
  version: number;
  updated_at: string;
  has_decided: boolean;
  categories: CookieCategoryPreferences;
};

export type CookieConsentResponse = {
  status: string;
  data: CookieConsent;
};

export type UpdateCookieConsentRequest = {
  analytics?: boolean;
  marketing?: boolean;
  preferences?: boolean;
};

export type PublicPrivacyConfig = {
  policy: {
    analytics_enabled: boolean;
    marketing_enabled: boolean;
    preferences_enabled: boolean;
  };
  integrations: {
    ga_measurement_id?: string | null;
    fb_pixel_id?: string | null;
  };
};

export type PublicPrivacyConfigResponse = {
  status: string;
  data: PublicPrivacyConfig;
};

const privacyService = {
  
  getCookieConsent: async (): Promise<CookieConsent> => {
    const response = await apiClient.get<CookieConsentResponse>(
      '/privacy/cookie-consent'
    );
    return response.data.data;
  },

  
  getPublicConfig: async (): Promise<PublicPrivacyConfig> => {
    const response = await apiClient.get<PublicPrivacyConfigResponse>(
      '/privacy/config'
    );
    return response.data.data;
  },

  
  updateCookieConsent: async (
    payload: UpdateCookieConsentRequest
  ): Promise<CookieConsent> => {
    const response = await apiClient.post<CookieConsentResponse>(
      '/privacy/cookie-consent',
      payload
    );
    return response.data.data;
  },
};

export default privacyService;

