// @ts-check
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

mongoose.Promise = global.Promise;
mongoose.level = "F";


const HeroSchema = new Schema({
  title: { type: String, required: true },
  subtitle: String,
  badge: String,
  mediaUrl: { type: String, required: true },
  ctas: [{ label: String, to: String, href: String }]
}, { _id: false });

const PillarSchema = new Schema({
  id: { type: String, required: true },
  icon: { type: String, required: true },
  title: { type: String, required: true },
  excerpt: String,
  to: String
}, { _id: false });

const TestimonialSchema = new Schema({
  id: String, quote: String, author: String, role: String, avatar: String
}, { _id: false });

const GallerySchema = new Schema({
  id: String, src: String, alt: String
}, { _id: false });

const FaqSchema = new Schema({
  q: String, a: String
}, { _id: false });

const PostLiteSchema = new Schema({
  id: String, title: String, date: String, category: String, teaser: String, cover: String, to: String
}, { _id: false });

const PartnerSchema = new Schema({
  id: String, name: String, logo: String, href: String
}, { _id: false });

const HomeSchema = new Schema({
  hero: { type: HeroSchema, required: true },
  pillars: { type: [PillarSchema], default: [] },
  testimonials: { type: [TestimonialSchema], default: [] },
  gallery: { type: [GallerySchema], default: [] },
  faq: { type: [FaqSchema], default: [] },
  posts: { type: [PostLiteSchema], default: [] },
  partners: { type: [PartnerSchema], default: [] },
  meta: { title: String, description: String, ogImage: String },
  updatedAt: { type: Date, default: Date.now }
}, { collection: 'home', versionKey: false });

HomeSchema.pre('save', function(next) {
  this.set('updatedAt', new Date());
  next();
});


var HomeModel = module.exports = mongoose.model('Home', HomeSchema);
