import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsIn, IsNotEmpty, IsOptional, IsUUID, Length } from 'class-validator';
import { EstadoUser } from './enum-user';

export class CreateUserDto {
  @ApiProperty({ example: 'cd88ac6a-2b0e-41bc-afd9-24b594cb8daf' })
  @IsUUID('all', { message: 'Empresa debe ser un UUID válido' })
  empresa_id: string;

  @ApiProperty({ example: '123456789012' })
  @IsOptional()
  @Length(3, 8, { message: 'RUC debe tener entre 3 y 8 caracteres' })
  ruc?: string;

  @ApiProperty({ example: 'username' })
  @IsNotEmpty({ message: 'Username es obligatorio' })
  @Length(3, 255, { message: 'Username debe tener entre 3 y 255 caracteres' })
  username: string;

  @ApiProperty({ example: 'John' })
  @IsNotEmpty({ message: 'Nombres es obligatorio' })
  @Length(3, 255, { message: 'Nombres debe tener entre 3 y 255 caracteres' })
  nombres: string;

  @ApiProperty({ example: 'Doe' })
  @IsOptional()
  @Length(3, 255, { message: 'Apellidos debe tener entre 3 y 255 caracteres' })
  apellidos?: string;

  @ApiProperty({ example: 'password' })
  @IsOptional()
  @Length(3, 255, { message: 'Password debe tener entre 3 y 255 caracteres' })
  password?: string;

  @ApiProperty({ example: 'password_funcional' })
  @IsOptional()
  @Length(3, 255, { message: 'Password funcional debe tener entre 3 y 255 caracteres' })
  passwordUserFuncional?: string;

  @ApiProperty({ enum: EstadoUser, example: EstadoUser.Pendiente })
  @IsNotEmpty({ message: 'Estado es obligatorio' })
  @IsIn([EstadoUser.Pendiente, EstadoUser.Inactivo, EstadoUser.Activo], {
    message: 'Estado debe ser Pendiente, Activo o Inactivo',
  })
  estado: EstadoUser;

  @ApiProperty({ example: 'email@example.com' })
  @IsEmail({}, { message: 'Email debe tener un formato válido' })
  @IsOptional()
  @Length(3, 80, { message: 'Email debe tener entre 3 y 80 caracteres' })
  email?: string;

  @ApiProperty({ example: '595981743120' })
  @IsOptional()
  @Length(12, 20, { message: 'Celular debe tener mínimo 12 y máximo 20 caracteres' })
  celular?: string;

  @ApiProperty({ example: '{..}' })
  @IsOptional()
  empresas?: string;

  @ApiProperty({ example: ['cd88ac6a-2b0e-41bc-afd9-24b594cb8daf'] })
  @IsOptional()
  perfiles?: Array<string>;

  @ApiProperty({ example: 'dark', description: 'Tema de la interfaz: light o dark' })
  @IsOptional()
  @IsIn(['light', 'dark'], { message: 'Tema debe ser light o dark' })
  tema?: string;

  @ApiProperty({ example: '1234', description: 'PIN de supervisor (4-6 dígitos). Enviar vacío para quitar.' })
  @IsOptional()
  pin_supervisor?: string;
}
