import { Type } from 'class-transformer'
import { IsArray, IsOptional, IsString, MaxLength, ValidateNested } from 'class-validator'

// Partner-editable settings. Margin, agreement terms, and documents are
// operator-controlled and intentionally NOT accepted here — a partner can edit
// its own contact profile and notification preferences, nothing that changes
// the commercial relationship.
class PartnerProfileDto {
  @IsOptional() @IsString() @MaxLength(200) legalName?: string
  @IsOptional() @IsString() @MaxLength(200) tradingName?: string
  @IsOptional() @IsString() @MaxLength(300) address?: string
  @IsOptional() @IsString() @MaxLength(2) country?: string
  @IsOptional() @IsString() @MaxLength(254) primaryEmail?: string
  @IsOptional() @IsString() @MaxLength(40) primaryPhone?: string
  @IsOptional() @IsString() @MaxLength(40) supportHotline?: string
  @IsOptional() @IsString() @MaxLength(200) website?: string
}

class NotificationPrefDto {
  @IsString() @MaxLength(120) event!: string
  @IsString() @MaxLength(40) cadence!: string
  @IsArray() @IsString({ each: true }) channels!: string[]
}

export class PartnerSettingsDto {
  @IsOptional() @ValidateNested() @Type(() => PartnerProfileDto)
  profile?: PartnerProfileDto

  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => NotificationPrefDto)
  notificationPrefs?: NotificationPrefDto[]
}
