import { Type } from 'class-transformer'
import {
  IsEmail,
  IsEnum,
  IsInt,
  IsOptional,
  IsString,
  Matches,
  Max,
  MaxLength,
  Min,
  MinLength,
  ValidateNested,
} from 'class-validator'

class ContactInfoDto {
  @IsOptional() @IsString() @MaxLength(200) primaryName?: string
  @IsOptional() @IsEmail() primaryEmail?: string
  @IsOptional() @IsEmail() billingEmail?: string
}

class BillingInfoDto {
  @IsOptional() @IsString() @MaxLength(200) companyName?: string
  @IsOptional() @IsString() @MaxLength(40) vatId?: string
  @IsOptional() @IsString() @MaxLength(2) country?: string
  @IsOptional() @IsEmail() contactEmail?: string
}

export class CreatePartnerDto {
  @IsString()
  @Matches(/^[a-z0-9]([a-z0-9-]{0,38}[a-z0-9])?$/, {
    message: 'slug must be lowercase, 2-40 chars, hyphen-separated',
  })
  slug!: string

  @IsString() @MinLength(2) @MaxLength(120)
  name!: string

  @IsString() @MinLength(3) @MaxLength(120)
  domain!: string

  @IsOptional() @IsEnum(['active', 'in-negotiation', 'paused', 'terminated'])
  status?: 'active' | 'in-negotiation' | 'paused' | 'terminated'

  @IsOptional() @IsInt() @Min(0) @Max(100)
  marginPct?: number

  @IsOptional() @ValidateNested() @Type(() => ContactInfoDto)
  contactInfo?: ContactInfoDto

  @IsOptional() @ValidateNested() @Type(() => BillingInfoDto)
  billingInfo?: BillingInfoDto
}
