import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsString,
  IsNotEmpty,
  IsOptional,
  IsInt,
  IsEnum,
  IsBoolean,
  Min,
  Matches,
} from 'class-validator';
import { CrmStageType, CrmActivityType } from '@prisma/client';

export class CreateStageDto {
  @ApiProperty({ description: 'Stage name', example: 'Новый лид' })
  @IsString()
  @IsNotEmpty()
  name: string;

  @ApiProperty({ description: 'Position in pipeline', example: 1 })
  @IsInt()
  @Min(0)
  position: number;

  @ApiPropertyOptional({ description: 'Hex color', example: '#3B82F6' })
  @IsString()
  @IsOptional()
  @Matches(/^#[0-9a-fA-F]{6}$/, { message: 'color must be a valid hex color (e.g. #3B82F6)' })
  color?: string;

  @ApiPropertyOptional({ enum: CrmStageType, default: 'OPEN' })
  @IsEnum(CrmStageType)
  @IsOptional()
  type?: CrmStageType;

  @ApiPropertyOptional({ enum: CrmActivityType })
  @IsEnum(CrmActivityType)
  @IsOptional()
  autoActivityType?: CrmActivityType;

  @ApiPropertyOptional({ description: 'Auto activity after N days' })
  @IsInt()
  @IsOptional()
  autoActivityDays?: number;

  @ApiPropertyOptional({ description: 'Days before deal considered stale' })
  @IsInt()
  @IsOptional()
  staleDays?: number;

  @ApiPropertyOptional({ description: 'Is default stage for new deals' })
  @IsBoolean()
  @IsOptional()
  isDefault?: boolean;
}
