import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
import { HydratedDocument, Types } from 'mongoose'

export type PartnerBrandingDocument = HydratedDocument<PartnerBranding>

// Whitelabel branding for a partner — one doc per partner. Kept in its own
// collection (not embedded on Partner) so the potentially-large email-template
// bodies stay off the partner hot path.
@Schema({ collection: 'partner_branding', timestamps: true })
export class PartnerBranding {
  @Prop({ type: Types.ObjectId, ref: 'Partner', required: true, unique: true, index: true })
  partnerId!: Types.ObjectId

  // The partner's own brand identity (shown in the partner console + on emails
  // its team sends — not what customers see).
  @Prop({
    type: {
      displayName: String,
      logoUrl: String,
      markUrl: String,
      faviconUrl: String,
      primaryColor: String,
      supportEmail: String,
      supportPhone: String,
      website: String,
      replyTo: String,
    },
    default: {},
  })
  identity!: {
    displayName?: string
    logoUrl?: string
    markUrl?: string
    faviconUrl?: string
    primaryColor?: string
    supportEmail?: string
    supportPhone?: string
    website?: string
    replyTo?: string
  }

  // Defaults pushed to every customer the partner provisions (label/detail/on).
  @Prop({ type: [{ label: String, detail: String, on: Boolean }], default: [] })
  customerDefaults!: Array<{ label: string; detail: string; on: boolean }>

  // Branded email templates (one per id). `body` may be large.
  @Prop({
    type: [{ id: String, name: String, subject: String, body: String, edited: String }],
    default: [],
  })
  emailTemplates!: Array<{ id: string; name: string; subject: string; body: string; edited: string }>
}

export const PartnerBrandingSchema = SchemaFactory.createForClass(PartnerBranding)
