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

import {
  SubscriptionsData,
  SubscriptionsSchema,
  UserSubscriptionActionPayload,
  UserSubscriptionActionResponse,
  UserSubscriptionActionResponseSchema,
} from "./types";

export const getSubscriptions = async () => {
  return http.get<SubscriptionsData>(API_ROUTES.subscriptions(), {
    tags: ["subscriptions"],
    schema: SubscriptionsSchema,
    revalidate: 0,
  });
};

export const performUserSubscriptionAction = async (
  payload: UserSubscriptionActionPayload
) => {
  const { subscriptionId, action } = payload;

  return http.post<UserSubscriptionActionResponse>(
    API_ROUTES.userSubscriptionAction(subscriptionId, action),
    payload,
    {
      tags: ["user-subscription-action"],
      schema: UserSubscriptionActionResponseSchema,
      revalidate: 0,
    }
  );
};
