import { IsString, IsNotEmpty, IsOptional, IsEmail, MaxLength, IsBoolean, IsEnum, IsArray, ValidateNested, ArrayMinSize } from 'class-validator';
import { Type } from 'class-transformer';
import { CompanyType } from '../entities/company.entity';
import { ProfileType } from '../entities/company-profile.entity';
import { IsValidPhone } from '../../../common/validators/is-phone-number.validator';

export class CompanyProfileInputDto {
  @IsEnum(ProfileType)
  type!: ProfileType;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  businessLicense?: string;
}

export class CreateCompanyWithProfileDto {
  @IsEnum(CompanyType)
  companyType!: CompanyType;

  @IsString()
  @IsNotEmpty()
  @MaxLength(200)
  companyName!: string;

  @IsOptional()
  @IsEmail()
  @MaxLength(150)
  companyEmail?: string;

  @IsOptional()
  @IsString()
  @MaxLength(20)
  @IsValidPhone()
  companyPhone?: string;

  @IsOptional()
  @IsString()
  @MaxLength(32)
  companyLocation?: string;

  @IsOptional()
  @IsString()
  companyAddress?: string;

  @IsOptional()
  @IsString()
  @MaxLength(10)
  tin?: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  vatNumber?: string;

  @IsOptional()
  @IsString()
  @MaxLength(16)
  fanNumber?: string;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  jobTitle?: string;

  @IsOptional()
  @IsBoolean()
  isPrimaryContact?: boolean;

  @IsOptional()
  attributes?: Record<string, any>;

  @IsOptional()
  @IsArray()
  @ArrayMinSize(1)
  @ValidateNested({ each: true })
  @Type(() => CompanyProfileInputDto)
  companyProfiles?: CompanyProfileInputDto[];
}
