import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsString,
  IsNotEmpty,
  IsArray,
  ValidateNested,
  IsIn,
  IsOptional,
  IsBoolean,
} from 'class-validator';
import { Type } from 'class-transformer';

class CardLayoutFieldDto {
  @ApiProperty({ example: 'amount' })
  @IsString()
  @IsNotEmpty()
  fieldKey: string;

  @ApiProperty({ enum: ['system', 'custom'] })
  @IsIn(['system', 'custom'])
  source: 'system' | 'custom';

  @ApiProperty({ enum: ['full', 'half'] })
  @IsIn(['full', 'half'])
  width: 'full' | 'half';
}

class CardLayoutBlockDto {
  @ApiProperty({ example: 'contact' })
  @IsString()
  @IsNotEmpty()
  blockKey: string;

  @ApiProperty({ example: 'Контакт' })
  @IsString()
  @IsNotEmpty()
  blockName: string;

  @ApiProperty({ type: [CardLayoutFieldDto] })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => CardLayoutFieldDto)
  fields: CardLayoutFieldDto[];
}

export class SetCardLayoutDto {
  @ApiProperty({ example: 'deal' })
  @IsString()
  @IsNotEmpty()
  entityType: string;

  @ApiProperty({ type: [CardLayoutBlockDto] })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => CardLayoutBlockDto)
  blocks: CardLayoutBlockDto[];

  @ApiPropertyOptional({ description: 'Also save as admin default (super_admin/club_admin only)' })
  @IsOptional()
  @IsBoolean()
  saveForAll?: boolean;
}
