'use strict';
import { Schema, model, connect } from 'mongoose';
enum Action {
  OPEN = "open",
  IN_PROGRESS = "in_progress",
  RESOLVED = "resolved",
  CLOSED = "closed"
}
var contactUsSchema = new Schema(
    {
        subject: {
            type: String,
        },
        description: {
            type: String,
        },
        attachments: {
            type: [String],
            default: []
        },
        user_id: {
            type: Schema.Types.ObjectId,   // ✅ use ObjectId
            ref: 'User',                   // ✅ reference to User collection
            required: true,
        },
        admin_id: {
            type: Schema.Types.ObjectId,   // (optional) same for admin if needed
            ref: 'Admin',
        },
        admin_notes: {
            type: String,
        },
        status: {
            type: String,
            enum: Action,
            default: Action.OPEN
        },
        ticket_id: {
            type: String,
            index: true,
            unique: true
        },
        is_deleted: {
            type: Boolean,
            default: false
        }
    },
    {
        timestamps: true,
    },
);

// Ensure a unique index on ticket_id at the database level
contactUsSchema.index({ ticket_id: 1 }, { unique: true });

let Contact = model('Contact', contactUsSchema)
module.exports = { Contact, contactUsSchema }
