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 IEventsPage extends Document {
  heroTitle: ILocalizedString;
  heroSubtitle: ILocalizedString;
  heroImage?: string;
  events: Array<{
    title: ILocalizedString;
    description: ILocalizedString;
    date: string;
    endDate?: string;
    venue: ILocalizedString;
    location: ILocalizedString;
    image?: string;
    isFeatured: boolean;
    links: Array<{
      label: ILocalizedString;
      url: string;
    }>;
  }>;
  updatedAt: Date;
}

const eventsPageSchema = new Schema<IEventsPage>(
  {
    heroTitle: {
      type: localizedStringSchema,
      default: { en: 'Events', zh: '活動' },
    },
    heroSubtitle: {
      type: localizedStringSchema,
      default: { en: '', zh: '' },
    },
    heroImage: String,
    events: [
      {
        title: { type: localizedStringSchema },
        description: { type: localizedStringSchema },
        date: { type: String, default: '' },
        endDate: String,
        venue: { type: localizedStringSchema },
        location: { type: localizedStringSchema },
        image: String,
        isFeatured: { type: Boolean, default: false },
        links: [
          {
            label: { type: localizedStringSchema },
            url: { type: String, default: '' },
          },
        ],
      },
    ],
  },
  {
    timestamps: true,
  }
);

export const EventsPage = mongoose.model<IEventsPage>('EventsPage', eventsPageSchema);
