import { IsIn, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';

/**
 * Bodies are complete HTML documents exported from the analysis hub, with their
 * styling and images embedded — the real ones run to about 1.7 MB. The cap sits
 * well above that but far below Fastify's 26 MB body limit, so an oversized
 * upload fails as a clear validation error rather than a dropped connection.
 */
const MAX_BODY = 8_000_000;
/** Covers arrive as data URIs from the editor, which is why this is large. */
const MAX_COVER = 4_000_000;

export class CreatePostDto {
  @IsString()
  @MaxLength(64)
  channelId!: string;

  @IsString()
  @MinLength(1)
  @MaxLength(300)
  title!: string;

  @IsOptional()
  @IsString()
  @MaxLength(600)
  excerpt?: string;

  @IsOptional()
  @IsString()
  @MaxLength(MAX_BODY)
  body?: string;

  @IsOptional()
  @IsString()
  @MaxLength(MAX_COVER)
  cover?: string;

  @IsOptional()
  @IsIn(['DRAFT', 'PUBLISHED'])
  status?: 'DRAFT' | 'PUBLISHED';

  /** Long read or short read of the same analysis. Defaults to the full one. */
  @IsOptional()
  @IsIn(['FULL', 'SHORT'])
  variant?: 'FULL' | 'SHORT';
}

export class UpdatePostDto {
  @IsOptional()
  @IsString()
  @MaxLength(64)
  channelId?: string;

  @IsOptional()
  @IsString()
  @MinLength(1)
  @MaxLength(300)
  title?: string;

  @IsOptional()
  @IsString()
  @MaxLength(600)
  excerpt?: string;

  @IsOptional()
  @IsString()
  @MaxLength(MAX_BODY)
  body?: string;

  @IsOptional()
  @IsString()
  @MaxLength(MAX_COVER)
  cover?: string;

  @IsOptional()
  @IsIn(['DRAFT', 'PUBLISHED'])
  status?: 'DRAFT' | 'PUBLISHED';

  @IsOptional()
  @IsIn(['FULL', 'SHORT'])
  variant?: 'FULL' | 'SHORT';
}
