import { ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsEmail,
  IsOptional,
  IsString,
  MaxLength,
  MinLength,
  ValidateNested,
} from 'class-validator';
import { CreateShopDto } from '../../users/dto/create-shop.dto';

/**
 * Register a store for the currently authenticated user (mobile app user → merchant).
 * This upgrades the existing USER to ADMIN and attaches a newly created shop.
 */
export class RegisterStoreMeDto {
  @ApiPropertyOptional({
    example: 'owner@yourstore.com',
    description: 'If omitted, uses the current user email.',
  })
  @IsOptional()
  @IsEmail()
  email?: string;

  @ApiPropertyOptional({
    example: 'Pass1234',
    description: 'Sets/updates password for portal login.',
  })
  @IsOptional()
  @IsString()
  @MinLength(4)
  @MaxLength(72)
  password?: string;

  @ValidateNested()
  @Type(() => CreateShopDto)
  shop!: CreateShopDto;
}
