import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsEnum, IsNotEmpty, IsOptional, IsString, IsBoolean, IsUrl, IsNumber, IsArray } from 'class-validator';
import { UserRole, UserStatus } from '../../../common/enum/UserRole.enum';
import { ApiKey } from 'modules/feature/api-key/entities/api-key.entity';
import { ClientEntity } from 'modules/client/entities/client.entity';
import { Ticket } from 'modules/ticket/entities/ticket.entity';
import { RoleEntity } from 'modules/role-permission/roles/entities/role.entity';

export class UserDto {
  @ApiProperty({ example: 1 })
  @IsNumber()
  id: number;

  @ApiProperty({ example: 'John' })
  @IsString()
  @IsNotEmpty()
  firstName: string;

  @ApiProperty({ example: 'Doe' })
  @IsString()
  @IsNotEmpty()
  lastName: string;

  @ApiProperty({ example: 'john.doe@example.com' })
  @IsEmail()
  email: string;

  @ApiProperty({ example: 'SecurePass123!' })
  @IsString()
  @IsNotEmpty()
  password: string;

  @ApiProperty({ enum: UserRole, example: UserRole.USER })
  @IsEnum(UserRole)
  role: UserRole;

  @ApiProperty({ type: () => ClientEntity, required: false })
  @IsOptional()
  client?: ClientEntity;

  @ApiProperty({ example: 2, required: false })
  @IsOptional()
  @IsNumber()
  clientId?: number;

  @ApiProperty({ enum: UserStatus, example: UserStatus.ACTIVE })
  @IsEnum(UserStatus)
  status: UserStatus;

  @ApiProperty({ type: () => [RoleEntity] })
  @IsOptional()
  @IsArray()
  roles: RoleEntity[];

  @ApiProperty({ example: 'referrer@example.com', required: false })
  @IsOptional()
  @IsEmail()
  referralMail?: string;

  @ApiProperty({
    example: 'https://cdn-icons-png.flaticon.com/512/149/149071.png',
    required: false,
  })
  @IsOptional()
  @IsUrl()
  picture?: string;

  @ApiProperty({ example: 'google-oauth-id', required: false })
  @IsOptional()
  @IsString()
  googleId?: string;

  @ApiProperty({ example: true, required: false })
  @IsOptional()
  @IsBoolean()
  isGoogleUser?: boolean;

  @ApiProperty({ type: () => [Ticket] })
  @IsOptional()
  @IsArray()
  assignedTickets: Ticket[];

  @ApiProperty({ type: () => [ApiKey] })
  @IsOptional()
  @IsArray()
  apiKeys: ApiKey[];

  @ApiProperty({ example: new Date().toISOString() })
  @IsOptional()
  createdAt: Date;

  @ApiProperty({ example: new Date().toISOString() })
  @IsOptional()
  updatedAt: Date;
}
