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

export interface IDashboardStats extends Document {
  _id: mongoose.Types.ObjectId;
  totalUsers: number;
  totalRevenue: number;
  activeSessions: number;
  conversionRate: number;
  recentActivity: Array<{
    id: string;
    action: string;
    timestamp: Date;
  }>;
  createdAt: Date;
  updatedAt: Date;
}

const DashboardStatsSchema = new Schema<IDashboardStats>({
  totalUsers: {
    type: Number,
    required: true,
    default: 0,
  },
  totalRevenue: {
    type: Number,
    required: true,
    default: 0,
  },
  activeSessions: {
    type: Number,
    required: true,
    default: 0,
  },
  conversionRate: {
    type: Number,
    required: true,
    default: 0,
  },
  recentActivity: [{
    id: {
      type: String,
      required: true,
    },
    action: {
      type: String,
      required: true,
    },
    timestamp: {
      type: Date,
      required: true,
      default: Date.now,
    },
  }],
}, {
  timestamps: true,
});

// Prevent duplicate model compilation
const DashboardStats = mongoose.models.DashboardStats || mongoose.model<IDashboardStats>('DashboardStats', DashboardStatsSchema);

export default DashboardStats;
