import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsBoolean, IsDefined, IsEmail, IsEnum, IsNotEmpty, IsNumber, IsObject, IsOptional, IsString, IsStrongPassword, MaxLength, MinLength, ValidateIf, ValidateNested } from "class-validator";
import { File } from "../chat-history/chat-history.validation";
import { ChangePasswordDto } from "../auth/auth.validation";

class UpdateSettingsDto {
	@ApiProperty({ example: true, description: 'isImageInsideChat', required: true })
	@IsString({ message: 'isImageInsideChat must be a boolean' })
	@IsNotEmpty({ message: 'isImageInsideChat cannot be empty' })
	isImageInsideChat: string;
}

class UpdateFullSettingsDto {
	@ApiProperty({ example: false, description: 'isFilter must be a boolean', required: false })
	@IsBoolean({ message: 'isFilter must be a boolean' })
	@IsOptional()
	isFilter: boolean;

	@ApiProperty({ example: false, description: 'isImageInsideChat must be a boolean', required: false })
	@IsBoolean({ message: 'isImageInsideChat must be a boolean' })
	@IsOptional()
	isImageInsideChat: boolean;
}

class UpdateSubscriptionDto {
	@ApiProperty({ example: 'free', required: false, description: 'Subscription plan', enum: ['free', 'premium'] })
	@IsEnum(['free', 'premium'], { message: 'Plan must be either free or premium' })
	@IsOptional()
	plan: 'free' | 'premium';

	@ApiProperty({ example: 10 })
	@IsNumber({}, { message: 'queryLimit must be a number' })
	@IsOptional()
	queryLimit: number;

	@ApiProperty({ example: 3 })
	@IsNumber({}, { message: 'imageLimit must be a number' })
	@IsOptional()
	imageLimit: number;

	@ApiProperty({ example: 1 })
	@IsNumber({}, { message: 'fileLimit must be a number' })
	@IsOptional()
	fileLimit: number;
}

export class UpdateUserDto {
	@ApiProperty({ example: 'John Doe' })
	@IsString({ message: 'Name must be a string' })
	@IsOptional()
	name: string;

	@ApiProperty({ example: 'EN', required: false, description: 'User language', enum: ['EN', 'HB'] })
	@IsEnum(['EN', 'HB'], { message: 'User language EN or HB' })
	@IsOptional()
	language: 'EN' | 'HB';

	@ApiProperty({ example: ChangePasswordDto, description: 'Update password', required: false })
	@IsObject({ message: 'Update password must be a object' })
	@ValidateIf(o => o.updatePassword !== undefined)
	@ValidateNested({ each: true, message: 'Update password must be a object' })
	@Type(() => ChangePasswordDto)
	updatePassword: ChangePasswordDto;

	@ApiProperty({ example: UpdateSettingsDto, description: 'Update settings', required: false })
	@IsObject({ message: 'Update settings must be a object' })
	@ValidateIf(o => o.updateSettings !== undefined)
	@ValidateNested({ each: true, message: 'Update settings must be a object' })
	@Type(() => UpdateSettingsDto)
	settings: UpdateSettingsDto;

	@ApiProperty({ example: 'https://lh3.googleusercontent.com/a/ACg8ocL6ENaRyKehVXK-br8c4HYs3ZIPS6ONCA5s191YGEC5=s96-c' })
	@IsString({ message: 'Image url must be a string' })
	@IsOptional()
	imageUrl: string;

	@ApiProperty({ example: '972550000000', required: false, description: 'Phone number for WhatsApp' })
	@IsString({ message: 'Phone number must be a string' })
	@IsOptional()
	phoneNumber?: string;
}

export class UpdateFullUserDto {
	@ApiProperty({ example: 'John Doe' })
	@IsString({ message: 'Name must be a string' })
	@IsOptional()
	name: string;

	@ApiProperty({ example: 'john@gmail.com' })
	@IsString({ message: 'Name must be a string' })
	@IsOptional()
	email: string;

	@ApiProperty({ example: true })
	@IsBoolean({ message: 'isVerified must be a boolean' })
	@IsOptional()
	isVerified: boolean;

	@ApiProperty({ example: false })
	@IsBoolean({ message: 'isBlocked must be a boolean' })
	@IsOptional()
	isBlocked: boolean;

	@ApiProperty({ example: ChangePasswordDto, description: 'Update password', required: false })
	@IsObject({ message: 'Update password must be a object' })
	@ValidateIf(o => o.updatePassword !== undefined)
	@ValidateNested({ each: true, message: 'Update password must be a object' })
	@Type(() => ChangePasswordDto)
	updatePassword: ChangePasswordDto;

	@ApiProperty({ example: UpdateFullSettingsDto, description: 'Update settings', required: false })
	@IsObject({ message: 'Update settings must be a object' })
	@ValidateIf(o => o.settings !== undefined)
	@ValidateNested({ each: true, message: 'Update settings must be a object' })
	@Type(() => UpdateFullSettingsDto)
	settings: UpdateFullSettingsDto;

	@ApiProperty({ example: UpdateSubscriptionDto, description: 'Update subscription', required: false })
	@ValidateIf(o => o.subscription !== undefined && o.subscription !== undefined)
	@ValidateNested({ each: true, message: 'Update subscription must be a object' })
	@Type(() => UpdateSubscriptionDto)
	subscription: UpdateSubscriptionDto;

	@ApiProperty({ example: 'https://lh3.googleusercontent.com/a/ACg8ocL6ENaRyKehVXK-br8c4HYs3ZIPS6ONCA5s191YGEC5=s96-c' })
	@IsString({ message: 'Image url must be a string' })
	@IsOptional()
	imageUrl: string;
}