/**
 * Changelog module — types and schemas.
 * Public product changelog entries managed by admins.
 */

import { z } from 'zod';

export type ChangelogCategory = 'feature' | 'improvement' | 'fix' | 'breaking' | 'security';

export interface ChangelogEntryDoc {
  id: string;
  productId: string;
  version: string; // semver: '1.2.0'
  title: string;
  body: string; // markdown
  categories: ChangelogCategory[];
  published: boolean;
  publishedAt: string | null;
  createdAt: string;
  updatedAt: string;
}

// ── Schemas ────────────────────────────────────────────────────

export const CreateChangelogSchema = z.object({
  version: z.string().min(1).max(50),
  title: z.string().min(1).max(200),
  body: z.string().max(10000).default(''),
  categories: z.array(z.enum(['feature', 'improvement', 'fix', 'breaking', 'security'])).min(1),
  published: z.boolean().default(false),
});

export const UpdateChangelogSchema = z.object({
  version: z.string().min(1).max(50).optional(),
  title: z.string().min(1).max(200).optional(),
  body: z.string().max(10000).optional(),
  categories: z
    .array(z.enum(['feature', 'improvement', 'fix', 'breaking', 'security']))
    .min(1)
    .optional(),
  published: z.boolean().optional(),
});

export type CreateChangelogInput = z.infer<typeof CreateChangelogSchema>;
export type UpdateChangelogInput = z.infer<typeof UpdateChangelogSchema>;
