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

export interface IStaticVideo extends Document {
  title: string;
  subtitle: string;
  video_url: string;
  status: boolean;
  createdAt: Date;
  updatedAt: Date;
}

const StaticVideoSchema = new Schema<IStaticVideo>(
  {
    title: {
      type: String,
      required: [true, 'Title is required'],
      trim: true,
      maxlength: [200, 'Title cannot exceed 200 characters']
    },
    subtitle: {
      type: String,
      required: [true, 'Subtitle is required'],
      trim: true,
      maxlength: [300, 'Subtitle cannot exceed 300 characters']
    },
    video_url: {
      type: String,
      required: [true, 'Video URL is required'],
      trim: true
    },
    status: {
      type: Boolean,
      default: true
    }
  },
  {
    timestamps: true
  }
);

StaticVideoSchema.pre('save', function (this: IStaticVideo) {
  if (this.title) {
    this.title = this.title.trim();
  }
  if (this.subtitle) {
    this.subtitle = this.subtitle.trim();
  }
  if (this.video_url) {
    this.video_url = this.video_url.trim();
  }
});

export default mongoose.models.StaticVideo || mongoose.model<IStaticVideo>('StaticVideo', StaticVideoSchema);
