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

export interface ILocalizedString {
  en: string;
  zh: string;
}

const localizedStringSchema = {
  en: { type: String, default: '' },
  zh: { type: String, default: '' },
};

export interface ISidebarContent extends Document {
  title: ILocalizedString;
  image: string;
  link?: string;
  type: 'partner' | 'ad';
  placement: 'left' | 'right' | 'both';
  order: number;
  isActive: boolean;
  createdAt: Date;
  updatedAt: Date;
}

const sidebarContentSchema = new Schema<ISidebarContent>(
  {
    title: { type: localizedStringSchema, required: true },
    image: { type: String, default: '' },
    link: { type: String },
    type: { type: String, enum: ['partner', 'ad'], required: true },
    placement: { type: String, enum: ['left', 'right', 'both'], default: 'both' },
    order: { type: Number, default: 0 },
    isActive: { type: Boolean, default: true },
  },
  { timestamps: true }
);

sidebarContentSchema.index({ isActive: 1, order: 1 });

export const SidebarContent = mongoose.model<ISidebarContent>('SidebarContent', sidebarContentSchema);
