export type PostStatus = 'draft' | 'published' | 'archived' | 'deleted';
export type BuildJobStatus = 'queued' | 'running' | 'success' | 'failed' | 'cancelled';

export type User = {
  id: string;
  username: string;
  createdAt: string;
  updatedAt: string;
  lastLoginAt?: string | null;
};

export type Post = {
  id: string;
  slug: string;
  title: string;
  summary: string;
  bodyMarkdown: string;
  status: PostStatus;
  tags: string[];
  cover: string;
  version: number;
  slugSource: string;
  slugLocked: boolean;
  publishedAt?: string | null;
  createdAt: string;
  updatedAt: string;
  deletedAt?: string | null;
};

export type PostInput = {
  slug: string;
  title: string;
  summary: string;
  bodyMarkdown: string;
  status: PostStatus;
  tags: string[];
  cover: string;
  slugSource: string;
  slugLocked: boolean;
  createdAt?: string | null;
};

export type BuildJob = {
  id: string;
  trigger: string;
  status: BuildJobStatus;
  postId?: string | null;
  startedAt?: string | null;
  finishedAt?: string | null;
  log: string;
  error: string;
  createdAt: string;
  createdBy?: string | null;
};

export type AuditLog = {
  id: string;
  actorId?: string | null;
  actorUsername: string;
  action: string;
  resourceType: string;
  resourceId: string;
  ipAddress: string;
  userAgent: string;
  details: Record<string, unknown>;
  createdAt: string;
};

export type LoginResponse = {
  user: User;
  expiresAt: string;
};

export type PostResponse = {
  post: Post;
  buildJob?: BuildJob | null;
};

export type PostsResponse = {
  posts: Post[];
  total: number;
};

export type BuildJobResponse = {
  buildJob: BuildJob;
};

export type SlugResponse = {
  slug: string;
};

export type DeletePostResponse = {
  ok: boolean;
  buildJob?: BuildJob | null;
};

export type AuditLogsResponse = {
  logs: AuditLog[];
  total: number;
};

export type UploadedImage = {
  key: string;
  url: string;
  markdown: string;
  filename: string;
  size: number;
  contentType: string;
};

export type ImageUploadResponse = {
  image: UploadedImage;
};
