"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvoiceSchema = exports.Invoice = void 0;
const mongoose_1 = require("@nestjs/mongoose");
const base_entity_1 = require("../../common/entities/base.entity");
let Invoice = class Invoice extends base_entity_1.BaseEntity {
    invoiceNumber;
    paymentId;
    receiptNumber;
    transactionId;
    feeAssignmentId;
    feeName;
    installment;
    studentId;
    studentName;
    studentUniqueId;
    classId;
    className;
    academicYearId;
    amount;
    fineAmount;
    totalPaid;
    balance;
    status;
    paymentMode;
    date;
    generatedBy;
    isActive;
    notes;
};
exports.Invoice = Invoice;
__decorate([
    (0, mongoose_1.Prop)({ required: true, trim: true }),
    __metadata("design:type", String)
], Invoice.prototype, "invoiceNumber", void 0);
__decorate([
    (0, mongoose_1.Prop)({ trim: true }),
    __metadata("design:type", String)
], Invoice.prototype, "paymentId", void 0);
__decorate([
    (0, mongoose_1.Prop)({ trim: true }),
    __metadata("design:type", String)
], Invoice.prototype, "receiptNumber", void 0);
__decorate([
    (0, mongoose_1.Prop)({ trim: true, maxlength: 200 }),
    __metadata("design:type", String)
], Invoice.prototype, "transactionId", void 0);
__decorate([
    (0, mongoose_1.Prop)({ trim: true }),
    __metadata("design:type", String)
], Invoice.prototype, "feeAssignmentId", void 0);
__decorate([
    (0, mongoose_1.Prop)({ trim: true }),
    __metadata("design:type", String)
], Invoice.prototype, "feeName", void 0);
__decorate([
    (0, mongoose_1.Prop)({ trim: true }),
    __metadata("design:type", String)
], Invoice.prototype, "installment", void 0);
__decorate([
    (0, mongoose_1.Prop)({ required: true }),
    __metadata("design:type", String)
], Invoice.prototype, "studentId", void 0);
__decorate([
    (0, mongoose_1.Prop)({ required: true, trim: true }),
    __metadata("design:type", String)
], Invoice.prototype, "studentName", void 0);
__decorate([
    (0, mongoose_1.Prop)({ required: true, trim: true }),
    __metadata("design:type", String)
], Invoice.prototype, "studentUniqueId", void 0);
__decorate([
    (0, mongoose_1.Prop)({ required: true }),
    __metadata("design:type", String)
], Invoice.prototype, "classId", void 0);
__decorate([
    (0, mongoose_1.Prop)({ required: true, trim: true }),
    __metadata("design:type", String)
], Invoice.prototype, "className", void 0);
__decorate([
    (0, mongoose_1.Prop)({ required: true }),
    __metadata("design:type", String)
], Invoice.prototype, "academicYearId", void 0);
__decorate([
    (0, mongoose_1.Prop)({ required: true, min: 0 }),
    __metadata("design:type", Number)
], Invoice.prototype, "amount", void 0);
__decorate([
    (0, mongoose_1.Prop)({ default: 0, min: 0 }),
    __metadata("design:type", Number)
], Invoice.prototype, "fineAmount", void 0);
__decorate([
    (0, mongoose_1.Prop)({ default: 0, min: 0 }),
    __metadata("design:type", Number)
], Invoice.prototype, "totalPaid", void 0);
__decorate([
    (0, mongoose_1.Prop)({ default: 0, min: 0 }),
    __metadata("design:type", Number)
], Invoice.prototype, "balance", void 0);
__decorate([
    (0, mongoose_1.Prop)({ required: true, enum: ['pending', 'paid', 'partial'], default: 'pending' }),
    __metadata("design:type", String)
], Invoice.prototype, "status", void 0);
__decorate([
    (0, mongoose_1.Prop)({ enum: ['cash', 'upi', 'cheque', 'bank_transfer', 'online'] }),
    __metadata("design:type", String)
], Invoice.prototype, "paymentMode", void 0);
__decorate([
    (0, mongoose_1.Prop)({ type: Date, default: () => new Date() }),
    __metadata("design:type", Date)
], Invoice.prototype, "date", void 0);
__decorate([
    (0, mongoose_1.Prop)({ required: true, trim: true }),
    __metadata("design:type", String)
], Invoice.prototype, "generatedBy", void 0);
__decorate([
    (0, mongoose_1.Prop)({ default: true }),
    __metadata("design:type", Boolean)
], Invoice.prototype, "isActive", void 0);
__decorate([
    (0, mongoose_1.Prop)({ trim: true, maxlength: 2000 }),
    __metadata("design:type", String)
], Invoice.prototype, "notes", void 0);
exports.Invoice = Invoice = __decorate([
    (0, mongoose_1.Schema)({ timestamps: true })
], Invoice);
exports.InvoiceSchema = mongoose_1.SchemaFactory.createForClass(Invoice);
exports.InvoiceSchema.index({ invoiceNumber: 1 }, { unique: true });
exports.InvoiceSchema.index({ paymentId: 1 }, { unique: true, sparse: true });
exports.InvoiceSchema.index({ receiptNumber: 1 }, { unique: true, sparse: true });
exports.InvoiceSchema.index({ transactionId: 1 }, { unique: true, sparse: true });
exports.InvoiceSchema.index({ feeAssignmentId: 1 }, { unique: true, sparse: true });
exports.InvoiceSchema.index({ studentId: 1, academicYearId: 1 });
exports.InvoiceSchema.index({ classId: 1, academicYearId: 1 });
exports.InvoiceSchema.index({ status: 1, date: -1 });
exports.InvoiceSchema.index({ academicYearId: 1 });
exports.InvoiceSchema.virtual('id').get(function () {
    return this._id?.toString?.() ?? String(this._id);
});
const jsonOpts = {
    versionKey: false,
    virtuals: true,
};
exports.InvoiceSchema.set('toJSON', jsonOpts);
exports.InvoiceSchema.set('toObject', jsonOpts);
//# sourceMappingURL=invoice.schema.js.map