import { IsEmail, IsOptional, IsString, Length } from 'class-validator'
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { IsNotEmpty } from 'class-validator'
import { Column } from 'typeorm'

export class CustomerData {
	@Column({
		type: 'varchar',
		length: 240,
		nullable: false,
	})
	@ApiProperty({ type: String })
	@IsNotEmpty()
	@IsString()
	@Length(2, 240)
	name: string

	/**
	 * Optional split name fields. `name` stays the single source of truth for
	 * display/search (backward compatible); when these are provided the service
	 * layer derives `name` from them.
	 */
	@Column({
		type: 'varchar',
		length: 120,
		nullable: true,
	})
	@ApiPropertyOptional({ type: String })
	@IsOptional()
	@IsString()
	@Length(1, 120)
	firstName?: string

	@Column({
		type: 'varchar',
		length: 120,
		nullable: true,
	})
	@ApiPropertyOptional({ type: String })
	@IsOptional()
	@IsString()
	@Length(1, 120)
	lastName?: string

	@Column({
		type: 'text',
		nullable: true,
	})
	@ApiPropertyOptional({ type: String, format: 'email' })
	@IsOptional()
	@IsEmail()
	email?: string

	@Column({
		type: 'text',
		nullable: true,
	})
	@ApiPropertyOptional({ type: String })
	@IsOptional()
	@IsString()
	phoneNumber?: string
}
