export const MANIFEST_SCHEMA_VERSION = 1 as const;
export const CANONICALIZATION_VERSION = "bglands-canonical-json-v1" as const;

export type ReleaseChannel = "stable" | "beta" | "canary";
export type LoaderId = "fabric" | "neoforge";
export type ArtifactKind = "client-mod" | "dependency-mod" | "config" | "resource-pack";

export interface DirectDistribution {
  type: "direct";
  url: string;
}

export interface CurseForgeDistribution {
  type: "curseforge";
  projectId: number;
  fileId: number;
}

export type Distribution = DirectDistribution | CurseForgeDistribution;

export interface SourceArtifact {
  id: string;
  kind: ArtifactKind;
  version: string;
  localFile: string;
  sourceIntegrity: {
    algorithm: "sha256";
    sha256: string;
    size: number;
  };
  fileName: string;
  installPath: string;
  required: boolean;
  restartRequired: boolean;
  distribution: Distribution;
}

export interface ReleaseSource {
  $schema?: string;
  schemaVersion: 1;
  product: "bglands-client";
  releaseId: string;
  version: string;
  channel: ReleaseChannel;
  publishedAt: string;
  minimumLauncherVersion: string;
  game: {
    minecraft: string;
    javaMajor: number;
    loader: {
      id: LoaderId;
      version: string;
    };
  };
  compatibility: {
    serverProtocol: number;
  };
  artifacts: SourceArtifact[];
}

export interface ReleaseArtifact extends Omit<SourceArtifact, "localFile" | "sourceIntegrity"> {
  integrity: {
    algorithm: "sha256";
    sha256: string;
    size: number;
  };
}

export interface ReleasePayload extends Omit<ReleaseSource, "$schema" | "schemaVersion" | "artifacts"> {
  artifacts: ReleaseArtifact[];
}

export interface ReleaseSignature {
  algorithm: "Ed25519";
  keyId: string;
  valueBase64: string;
}

export interface ReleaseManifest {
  $schema: string;
  schemaVersion: 1;
  payload: ReleasePayload;
  integrity: {
    canonicalization: typeof CANONICALIZATION_VERSION;
    algorithm: "sha256";
    payloadSha256: string;
  };
  signature: ReleaseSignature | null;
}
