// src/modules/contact/contacts.model.ts

import { Schema, model } from 'mongoose';
import { paginate, toJSON } from '@/shared/utils/plugins/index';
import {
  IBankAccountDoc,
  IBankAccountModel,
} from '@/modules/bankAccount/bankAccount.interface';
import { BankAccountType, Status } from '@/shared/constants/enum.constant';

const bankAccountSchema = new Schema<IBankAccountDoc>(
  {
    company: {
      type: Schema.Types.ObjectId,
      ref: 'Company',
    },
    bankName: { type: String, trim: true },
    accountNumber: { type: Number },
    accountHolderName: { type: String, trim: true },
    ifscCode: { type: String },
    branch: { type: String },
    accountType: {
      type: String,
      enum: Object.values(BankAccountType),
      default: BankAccountType.SAVINGS,
    },
    status: {
      type: String,
      enum: Object.values(Status),
      default: Status.ACTIVE,
    },
    isDeleted: {
      type: Boolean,
      default: false,
    },
    createdBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
    updatedBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
  },

  {
    timestamps: true,
  },
);

bankAccountSchema.plugin(toJSON);
bankAccountSchema.plugin(paginate);

export const BankAccount = model<IBankAccountDoc, IBankAccountModel>(
  'BankAccount',
  bankAccountSchema,
);
