const require_utils_errors_ErrorsClass = require('../utils/errors/ErrorsClass.cjs');
const require_models_audit_model = require('../models/audit.model.cjs');

//#region src/services/audit.service.ts
/**
* Creates a new audit in the database.
* @param audit - The audit data to create.
* @returns The created audit.
*/
const createAudit = async (audit) => {
	return await require_models_audit_model.AuditModel.create(audit);
};
/**
* Finds an audit by its ID.
* @param auditId - The ID of the audit to find.
* @returns The audit matching the ID.
*/
const getAuditById = async (auditId) => {
	const audit = await require_models_audit_model.AuditModel.findById(auditId);
	if (!audit) throw new require_utils_errors_ErrorsClass.GenericError("AUDIT_NOT_DEFINED", { auditId });
	return audit;
};
/**
* Finds audits by user ID.
* @param userId - The ID of the user.
* @param limit - Number of documents to limit.
* @param skip - Number of documents to skip.
* @returns List of audits for the user.
*/
const findAuditsByUserId = async (userId, limit = 100, skip = 0) => {
	return await require_models_audit_model.AuditModel.find({ userId }).sort({ createdAt: -1 }).skip(skip).limit(limit);
};
/**
* Finds audits by project ID.
* @param projectId - The ID of the project.
* @param limit - Number of documents to limit.
* @param skip - Number of documents to skip.
* @returns List of audits for the project.
*/
const findAuditsByProjectId = async (projectId, limit = 100, skip = 0) => {
	return await require_models_audit_model.AuditModel.find({ projectId }).sort({ createdAt: -1 }).skip(skip).limit(limit);
};

//#endregion
exports.createAudit = createAudit;
exports.findAuditsByProjectId = findAuditsByProjectId;
exports.findAuditsByUserId = findAuditsByUserId;
exports.getAuditById = getAuditById;
//# sourceMappingURL=audit.service.cjs.map