import { Schema, model } from 'mongoose';

import { ISubCompanyDoc, ISubCompanyModel } from '@/modules/subCompany/subCompany.interface';
import { paginate, toJSON } from '@/shared/utils/plugins';

const subCompanySchema = new Schema<ISubCompanyDoc>(
  {
    name: { type: String, required: true },
    description: { type: String },
    address: { type: String },
    phone: { type: String },
    createdBy: { type: Schema.Types.ObjectId, required: true, ref: 'User' },
    updatedBy: { type: Schema.Types.ObjectId, ref: 'User' },
    company: { type: Schema.Types.ObjectId, required: true, ref: 'Company' },
  },
  {
    timestamps: true,
  },
);


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

export const SubCompany = model<ISubCompanyDoc, ISubCompanyModel>('SubCompany', subCompanySchema);
