import { cacheLife, cacheTag } from "next/cache"
import type { AccountPayload } from "@codeflash-ai/common"
import { getAllOptimizationEvents, getRepositoriesWithStagingEvents } from "./action"

export async function getCachedInitialEvents(accountKey: string, payload: AccountPayload) {
  "use cache"
  cacheLife("frequent")
  cacheTag(`review-events:${accountKey}`)

  return getAllOptimizationEvents({ payload, page: 1, pageSize: 10 })
}

export async function getCachedRepositories(accountKey: string, payload: AccountPayload) {
  "use cache"
  cacheLife("frequent")
  cacheTag(`review-repos:${accountKey}`)

  return getRepositoriesWithStagingEvents(payload)
}
