import { MEMBERS_MIN_LENGTH, NAME_MAX_LENGTH, NAME_MIN_LENGTH } from "../utils/validation/validateOrganization.mjs";
import { planSchema } from "./plans.schema.mjs";
import { Schema } from "mongoose";

//#region src/schemas/organization.schema.ts
const organizationSchema = new Schema({
	name: {
		type: String,
		required: true,
		minlength: NAME_MIN_LENGTH,
		maxlength: NAME_MAX_LENGTH
	},
	membersIds: {
		type: [Schema.Types.ObjectId],
		ref: "User",
		required: true,
		minlength: MEMBERS_MIN_LENGTH
	},
	adminsIds: {
		type: [Schema.Types.ObjectId],
		ref: "User",
		required: true,
		minlength: MEMBERS_MIN_LENGTH
	},
	creatorId: {
		type: Schema.Types.ObjectId,
		ref: "User",
		required: true
	},
	plan: { type: planSchema }
}, {
	timestamps: true,
	toJSON: {
		virtuals: true,
		versionKey: false,
		transform(_doc, ret) {
			const { _id, ...rest } = ret;
			return {
				...rest,
				id: _id.toString()
			};
		}
	},
	toObject: {
		virtuals: true,
		transform(_doc, ret) {
			const { _id, ...rest } = ret;
			return {
				...rest,
				id: _id
			};
		}
	}
});
organizationSchema.virtual("id").get(function() {
	return this._id.toString();
});

//#endregion
export { organizationSchema };
//# sourceMappingURL=organization.schema.mjs.map