const mongoose = require('mongoose') const mongoosePaginate = require('mongoose-paginate-v2') const timestamp = require('mongoose-timestamp') const bookingServiceSchema = new mongoose.Schema({ serviceId: { type: String, required: true }, title: { type: String, required: true, trim: true }, price: { type: Number, required: true }, image: { type: String, default: null } }, { _id: false }) const bookingTimeRangeSchema = new mongoose.Schema({ start_time: { type: String, required: true }, end_time: { type: String, required: true } }, { _id: false }) const bookingWeeklyScheduleSchema = new mongoose.Schema({ day: { type: String, enum: ['sat', 'sun', 'mon', 'tue', 'wed', 'thu', 'fri'], required: true }, ranges: { type: [bookingTimeRangeSchema], default: [] } }, { _id: false }) const bookingConfigSchema = new mongoose.Schema({ owner: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true, index: true }, name: { type: String, required: true, trim: true }, services: { type: [bookingServiceSchema], default: [] }, weeklySchedule: { type: [bookingWeeklyScheduleSchema], default: [] }, holidayDates: { type: [Date], default: [] }, depositRequired: { type: Boolean, default: true }, // تعداد هفته‌هایی که برنامه هفتگی تکرار میشه (خالی = نامحدود)؛ بعد از پایانش کانفیگ به‌صورت خودکار inactive میشه و مالکش نوتیف میگیره weeklyRepeatCount: { type: Number, default: null, min: 1 }, // زمانی که شمارش تکرار هفتگی از اون شروع شده (هر بار فعال‌سازی/تمدید ریست میشه) repeatStartedAt: { type: Date, default: null }, status: { type: String, enum: ['draft', 'active', 'inactive'], default: 'draft', index: true } }) bookingConfigSchema.plugin(timestamp) bookingConfigSchema.plugin(mongoosePaginate) const BookingConfigModel = mongoose.model('BookingConfig', bookingConfigSchema) module.exports = BookingConfigModel