import { readFileSync } from "node:fs"
import { join } from "node:path"

export interface ReleaseCommit {
  sha: string
  shortSha: string
  subject: string
  author: string
  type: string
}

export interface ReleaseManifest {
  version: string
  tag: string
  publishedAt: string | null
  releaseUrl: string
  commits: ReleaseCommit[]
}

const fallbackManifest: ReleaseManifest = {
  version: "1.0.0",
  tag: "v1.0.0",
  publishedAt: null,
  releaseUrl: "",
  commits: [],
}

export function readReleaseManifest(): ReleaseManifest {
  try {
    const filePath = join(process.cwd(), "public", "release-manifest.json")
    const raw = readFileSync(filePath, "utf8")
    return JSON.parse(raw) as ReleaseManifest
  } catch {
    return fallbackManifest
  }
}
