import { NAMES_MAX_LENGTH, NAMES_MIN_LENGTH } from "../utils/validation/validateUser.mjs";
import { Schema } from "mongoose";
import validator from "validator";

//#region src/schemas/user.schema.ts
const userSchema = new Schema({
	email: {
		type: String,
		required: true,
		unique: true,
		validate: [validator.isEmail, "Please fill a valid email address"],
		lowercase: true,
		trim: true
	},
	name: {
		type: String,
		maxlength: NAMES_MAX_LENGTH,
		minlength: NAMES_MIN_LENGTH
	},
	phone: {
		type: String,
		maxlength: 20
	},
	customerId: {
		type: String,
		required: false
	},
	emailsList: {
		type: { newsLetter: {
			type: Boolean,
			default: false
		} },
		required: false
	},
	role: {
		type: String,
		enum: ["admin", "user"],
		default: "user",
		required: false
	},
	lastLoginMethod: {
		type: String,
		enum: [
			"email",
			"google",
			"github"
		],
		required: false
	},
	lang: {
		type: String,
		required: false
	},
	dateOfBirth: {
		type: Date,
		required: false
	}
}, {
	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
			};
		}
	}
});

//#endregion
export { userSchema };
//# sourceMappingURL=user.schema.mjs.map