import { http } from "@/shared/api/httpClient";
import { API_ROUTES } from "@/shared/constants/api-routes";

import {
  GetMyChatSettingsResponseSchema,
  type IChatSettings,
  type IGetMyChatSettingsResponse,
  type IUpdateMyChatSettingsResponse,
  UpdateMyChatSettingsResponseSchema,
} from "./types";

/**
 * Fetch current user's chat settings (server-side with httpOnly cookie access)
 */
export const getMyChatSettings =
  async (): Promise<IGetMyChatSettingsResponse> => {
    return http.get<IGetMyChatSettingsResponse>(
      API_ROUTES.getMyChatSettings(),
      {
        tags: ["profile", "chat-settings"],
        schema: GetMyChatSettingsResponseSchema,
        revalidate: 0,
      }
    );
  };

/**
 * Update current user's chat settings (client-side)
 */
export const updateMyChatSettings = async (
  settings: IChatSettings
): Promise<IUpdateMyChatSettingsResponse> => {
  return http.put<IUpdateMyChatSettingsResponse>(
    API_ROUTES.updateMyChatSettings(),
    settings,
    {
      tags: ["profile", "chat-settings"],
      schema: UpdateMyChatSettingsResponseSchema,
      revalidate: 0,
    }
  );
};
