import { GenericError } from "../utils/errors/ErrorsClass.mjs";
import { AuditModel } from "../models/audit.model.mjs";

//#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 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 AuditModel.findById(auditId);
	if (!audit) throw new 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 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 AuditModel.find({ projectId }).sort({ createdAt: -1 }).skip(skip).limit(limit);
};

//#endregion
export { createAudit, findAuditsByProjectId, findAuditsByUserId, getAuditById };
//# sourceMappingURL=audit.service.mjs.map