import { Schema, model } from 'mongoose';
import {
  IFast2smsDoc,
  IFast2smsModel,
} from '@/modules/communication/fast2sms/fast2sms.interface.js';
import { paginate, toJSON } from '@/shared/utils/plugins/index.js';
import { Status, TriggerPoint } from '@/shared/constants/enum.constant';

const fast2smsSchema = new Schema<IFast2smsDoc>(
  {
    companyId: { type: Schema.Types.ObjectId, ref: 'Company' },
    templateId: {
      type: String,
    },
    fast2smsStatus: {
      type: String,
      enum: Object.values(Status),
      default: Status.ACTIVE,
    },
    status: {
      type: String,
      enum: Object.values(Status),
      default: Status.ACTIVE,
    },
    variableCount: {
      type: Number,
    },

    message: {
      type: String,
    },
    isDefault: {
      type: Boolean,
      default: false,
    },
    triggerPoint: {
      type: String,
      enum: Object.values(TriggerPoint),
    },
  },
  {
    timestamps: true,
  },
);

// add plugin that converts mongoose to json
fast2smsSchema.plugin(toJSON);
fast2smsSchema.plugin(paginate);

export const Fast2sms = model<IFast2smsDoc, IFast2smsModel>(
  'Fast2sms',
  fast2smsSchema,
);
