import { MEMBERS_MIN_LENGTH, NAME_MAX_LENGTH, NAME_MIN_LENGTH } from "../utils/validation/validateProject.mjs";
import { Schema } from "mongoose";
import { Locales } from "@intlayer/types";

//#region src/schemas/project.schema.ts
const oAuth2AccessSchema = new Schema({
	clientId: {
		type: String,
		required: true
	},
	clientSecret: {
		type: String,
		required: true
	},
	userId: {
		type: Schema.Types.ObjectId,
		ref: "User",
		required: true
	},
	name: {
		type: String,
		required: true
	},
	expiresAt: { type: Date },
	accessToken: {
		type: [String],
		required: true,
		default: []
	},
	grants: {
		type: [String],
		required: true,
		default: []
	}
}, { timestamps: true });
const projectConfigSchema = new Schema({
	internationalization: {
		locales: {
			type: [String],
			enum: Object.values(Locales.ALL_LOCALES),
			required: true
		},
		defaultLocale: {
			type: String,
			enum: Object.values(Locales.ALL_LOCALES)
		}
	},
	editor: {
		applicationURL: { type: String },
		cmsURL: { type: String }
	}
}, { _id: false });
const projectSchema = new Schema({
	organizationId: {
		type: Schema.Types.ObjectId,
		ref: "Organization",
		required: true
	},
	name: {
		type: String,
		required: true,
		minlength: NAME_MIN_LENGTH,
		maxlength: NAME_MAX_LENGTH
	},
	configuration: projectConfigSchema,
	oAuth2Access: [oAuth2AccessSchema],
	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
	}
}, {
	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 { projectSchema };
//# sourceMappingURL=project.schema.mjs.map