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

class BrandIdentityDto {
  @IsOptional() @IsString() @MaxLength(120) displayName?: string
  @IsOptional() @IsString() @MaxLength(500) logoUrl?: string
  @IsOptional() @IsString() @MaxLength(500) markUrl?: string
  @IsOptional() @IsString() @MaxLength(500) faviconUrl?: string
  @IsOptional() @IsString() @Matches(/^(#[0-9a-fA-F]{6})?$/, { message: 'primaryColor must be a #rrggbb hex or empty' })
  primaryColor?: string
  @IsOptional() @IsString() @MaxLength(254) supportEmail?: string
  @IsOptional() @IsString() @MaxLength(40) supportPhone?: string
  @IsOptional() @IsString() @MaxLength(200) website?: string
  @IsOptional() @IsString() @MaxLength(254) replyTo?: string
}

class CustomerDefaultDto {
  @IsString() @MaxLength(120) label!: string
  @IsOptional() @IsString() @MaxLength(300) detail?: string
  @IsBoolean() on!: boolean
}

class EmailTemplateDto {
  @IsString() @MaxLength(80) id!: string
  @IsString() @MaxLength(160) name!: string
  @IsOptional() @IsString() @MaxLength(300) subject?: string
  @IsOptional() @IsString() @MaxLength(20000) body?: string
  @IsOptional() @IsString() @MaxLength(40) edited?: string
}

export class PartnerBrandingDto {
  @IsOptional() @ValidateNested() @Type(() => BrandIdentityDto)
  identity?: BrandIdentityDto

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

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