import { Schema, model } from 'mongoose';
import { paginate, toJSON } from '@/shared/utils/plugins';
import {
  IClickStatsDoc,
  IClickStatsModel,
  ClickAction,
  ClickType,
} from './clickStats.interface';

const clickStatsSchema = new Schema<IClickStatsDoc>(
  {
    type: {
      type: String,
      enum: Object.values(ClickType),
      required: true,
    },
    action: {
      type: String,
      enum: Object.values(ClickAction),
      required: true,
    },
    propertyId: {
      type: Schema.Types.ObjectId,
      ref: 'IndividualProperty',
      required: true,
    },
    companyId: {
      type: Schema.Types.ObjectId,
      ref: 'Company',
    },
    createdBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
    deviceInfo: {
      type: String,
      default: '',
    },
  },
  {
    timestamps: true,
  },
);

clickStatsSchema.plugin(toJSON);
clickStatsSchema.plugin(paginate);

export const ClickStats = model<IClickStatsDoc, IClickStatsModel>(
  'ClickStats',
  clickStatsSchema,
);
