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

export interface IManualMenuItem {
  name: string;
  purpose: string;
}

export interface IManualSection {
  id: string;
  icon: string;
  title: string;
  description: string;
  steps: string[];
}

export interface IManualFaqItem {
  q: string;
  a: string;
}

export interface IManualContent extends Document {
  title: string;
  subtitle: string;
  quickStart: string[];
  menuMap: IManualMenuItem[];
  sections: IManualSection[];
  faq: IManualFaqItem[];
  updatedBy?: mongoose.Types.ObjectId;
  createdAt: Date;
  updatedAt: Date;
}

const manualMenuItemSchema = new Schema<IManualMenuItem>(
  {
    name: { type: String, required: true, trim: true },
    purpose: { type: String, required: true, trim: true },
  },
  { _id: false }
);

const manualSectionSchema = new Schema<IManualSection>(
  {
    id: { type: String, required: true, trim: true },
    icon: { type: String, required: true, trim: true },
    title: { type: String, required: true, trim: true },
    description: { type: String, required: true, trim: true },
    steps: { type: [String], default: [] },
  },
  { _id: false }
);

const manualFaqSchema = new Schema<IManualFaqItem>(
  {
    q: { type: String, required: true, trim: true },
    a: { type: String, required: true, trim: true },
  },
  { _id: false }
);

const manualContentSchema = new Schema<IManualContent>(
  {
    title: { type: String, required: true, trim: true },
    subtitle: { type: String, required: true, trim: true },
    quickStart: { type: [String], default: [] },
    menuMap: { type: [manualMenuItemSchema], default: [] },
    sections: { type: [manualSectionSchema], default: [] },
    faq: { type: [manualFaqSchema], default: [] },
    updatedBy: { type: Schema.Types.ObjectId, ref: 'User' },
  },
  { timestamps: true }
);

export default mongoose.model<IManualContent>('ManualContent', manualContentSchema);
