import { privateMutator } from "../privateClient";
import type { Post } from "../generated/private/models/post";
import type { CursorPaginated } from "./feed";

export type HubSortOption = "newest" | "top";
export type HubTimeOption = "1h" | "6h" | "day" | "week" | "month" | "year" | "all" | "custom";

export interface HubPostsParams {
  hub: number;
  cursor?: string | null;
  tag?: number | null;
  sort?: HubSortOption;
  time?: HubTimeOption;
  start?: string;
  end?: string;
}

export const apiSocialHubPostsCursor = (
  params: HubPostsParams,
  signal?: AbortSignal,
) =>
  privateMutator<CursorPaginated<Post>>({
    url: `/api/social/posts/`,
    method: "GET",
    params: {
      hub: params.hub,
      cursor: params.cursor ?? undefined,
      tag: params.tag ?? undefined,
      sort: params.sort ?? undefined,
      time: params.time ?? undefined,
      start: params.start ?? undefined,
      end: params.end ?? undefined,
    },
    signal,
  });

export const hubPostsQueryKey = (
  hubId: number,
  sort: HubSortOption,
  time: HubTimeOption,
  start?: string,
  end?: string,
) => ["social", "hubs", hubId, "posts", sort, time, start ?? null, end ?? null] as const;
