import { ApiProperty } from '@nestjs/swagger';
import { IsBoolean, IsEnum, IsInt, IsNotEmpty, IsOptional } from 'class-validator';

/**
 * Sync strategy for copying template changes to program
 */
export enum SyncStrategy {
  /** Replace all sections and questions (delete existing, clone fresh from template) */
  REPLACE_ALL = 'REPLACE_ALL',
  
  /** Merge template changes with existing program data (add new, update matching, keep extra) */
  MERGE = 'MERGE',
  
  /** Add only new sections/questions from template (no updates or deletions) */
  ADD_NEW_ONLY = 'ADD_NEW_ONLY',
}

/**
 * DTO for syncing template changes to a specific program (Option B workflow)
 */
export class SyncFromTemplateDto {
  @ApiProperty({
    description: 'Program ID to sync template changes to (optional - set from route param)',
    example: 1144,
    required: false,
  })
  @IsOptional()
  @IsInt()
  programId?: number;

  @ApiProperty({
    description: 'Template ID to sync from (optional - uses program\'s templateId if not provided)',
    example: 5,
    required: false,
  })
  @IsOptional()
  @IsInt()
  templateId?: number;

  @ApiProperty({
    description: 'Sync strategy - how to merge template changes with program',
    enum: SyncStrategy,
    default: SyncStrategy.MERGE,
    example: SyncStrategy.MERGE,
    required: false,
  })
  @IsOptional()
  @IsEnum(SyncStrategy)
  strategy?: SyncStrategy;

  @ApiProperty({
    description: 'Backup existing program form before sync (creates soft-deleted snapshot)',
    default: true,
    required: false,
  })
  @IsOptional()
  @IsBoolean()
  createBackup?: boolean;

  @ApiProperty({
    description: 'Preview mode - returns diff without applying changes',
    default: false,
    required: false,
  })
  @IsOptional()
  @IsBoolean()
  previewOnly?: boolean;
}
