/**
 * BrandKit Model
 *
 * Top-level "project" entity. A BrandKit groups all branded assets for a company —
 * business info, logos, colours, typography — and tracks overall completion.
 */

import mongoose, { Schema, Document } from 'mongoose';

export type BrandKitStatus = 'draft' | 'in-progress' | 'completed';

export interface IBrandKit extends Document {
  companyId: string;

  // ── Kit identity ──
  name: string;
  tagline?: string;
  description?: string;

  // ── Business information (snapshot from BusinessProfile, editable override) ──
  businessName?: string;
  industry?: string;
  website?: string;
  email?: string;
  phone?: string;
  alternatePhone?: string;
  address?: {
    street?: string;
    city?: string;
    state?: string;
    country?: string;
    pincode?: string;
  };
  contactPerson?: {
    name?: string;
    designation?: string;
    email?: string;
    phone?: string;
  };
  gstNumber?: string;
  registrationNumber?: string;
  socialMedia?: {
    website?: string;
    linkedin?: string;
    twitter?: string;
    facebook?: string;
    instagram?: string;
  };

  // ── Logo references (points to BrandAsset IDs or direct URLs) ──
  primaryLogo?: string;
  secondaryLogo?: string;
  iconLogo?: string;
  monochromeLogo?: string;
  lightLogo?: string;
  darkLogo?: string;

  // ── Colour palette ──
  primaryColor: string;
  secondaryColor: string;
  accentColor?: string;
  backgroundColor?: string;
  textColor?: string;
  additionalColors?: string[];

  // ── Typography ──
  headingFont?: string;
  bodyFont?: string;
  accentFont?: string;

  // ── Brand personality (snapshot from Brand module) ──
  personalityPrimary?: string[];
  personalitySecondary?: string[];
  voiceDescription?: string;
  voiceDos?: string[];
  voiceDonts?: string[];

  // ── Status & progress ──
  status: BrandKitStatus;
  completionPercentage: number;
  assetCount: number;

  // ── Audit ──
  createdBy?: string;
  updatedBy?: string;

  createdAt: Date;
  updatedAt: Date;
}

const BrandKitSchema = new Schema<IBrandKit>(
  {
    companyId: {
      type: String,
      required: [true, 'Company ID is required'],
      index: true,
    },
    // ── Kit identity ──
    name: {
      type: String,
      required: [true, 'Brand kit name is required'],
      trim: true,
      maxlength: [120, 'Name cannot exceed 120 characters'],
    },
    tagline: { type: String, trim: true, maxlength: 200 },
    description: { type: String, trim: true, maxlength: 1000 },

    // ── Business information ──
    businessName: { type: String, trim: true },
    industry: { type: String, trim: true },
    website: { type: String, trim: true },
    email: { type: String, trim: true },
    phone: { type: String, trim: true },
    alternatePhone: { type: String, trim: true },
    address: {
      street: String,
      city: String,
      state: String,
      country: String,
      pincode: String,
    },
    contactPerson: {
      name: String,
      designation: String,
      email: String,
      phone: String,
    },
    gstNumber: { type: String, trim: true },
    registrationNumber: { type: String, trim: true },
    socialMedia: {
      website: String,
      linkedin: String,
      twitter: String,
      facebook: String,
      instagram: String,
    },

    // ── Logo references ──
    primaryLogo: String,
    secondaryLogo: String,
    iconLogo: String,
    monochromeLogo: String,
    lightLogo: String,
    darkLogo: String,

    // ── Colour palette ──
    primaryColor: { type: String, default: '#0F2040' },
    secondaryColor: { type: String, default: '#D4AF37' },
    accentColor: String,
    backgroundColor: String,
    textColor: String,
    additionalColors: [String],

    // ── Typography ──
    headingFont: { type: String, default: 'inter' },
    bodyFont: { type: String, default: 'inter' },
    accentFont: String,

    // ── Brand personality ──
    personalityPrimary: [String],
    personalitySecondary: [String],
    voiceDescription: String,
    voiceDos: [String],
    voiceDonts: [String],

    // ── Status & progress ──
    status: {
      type: String,
      enum: ['draft', 'in-progress', 'completed'],
      default: 'draft',
    },
    completionPercentage: { type: Number, default: 0, min: 0, max: 100 },
    assetCount: { type: Number, default: 0 },

    // ── Audit ──
    createdBy: String,
    updatedBy: String,
  },
  { timestamps: true }
);

BrandKitSchema.index({ companyId: 1, status: 1 });

export const BrandKit = mongoose.model<IBrandKit>('BrandKit', BrandKitSchema);