import { addLog } from "./log";

export const addKeberatan = async ({ noSanksi, ptId }, data) => {
	try {
		const res = await fetch(`http://localhost:5000/keberatan/add?noSanksi=${noSanksi}&ptId=${ptId}`, {
			method: "POST",
			body: data,
		});
		const result = await res.json();
		console.log(result);
		// addLog({ status: "SUCCESS", action: "CREATE", from: { id: result.added._id, data: "keberatan" }, description: "membuat permohonan keberatan" });
		return result;
	} catch (error) {
		console.log("error", error);
		addLog({ status: "FAIL", action: "CREATE", from: { data: "keberatan" }, description: error.message || "membuat permohonan keberatan" });
		return false;
	}
};

export const addJawabanKeberatan = async ({ noSanksi, ptId }, data) => {
	try {
		const res = await fetch(`http://localhost:5000/keberatan/jawaban/add?noSanksi=${noSanksi}&ptId=${ptId}`, {
			method: "POST",
			body: data,
		});
		const result = await res.json();
		console.log(result);
		// addLog({ status: "SUCCESS", action: "CREATE", from: { id: result.added._id, data: "keberatan" }, description: "membuat permohonan keberatan" });
		return result;
	} catch (error) {
		console.log("error", error);
		addLog({ status: "FAIL", action: "CREATE", from: { data: "keberatan" }, description: error.message || "membuat permohonan keberatan" });
		return false;
	}
};
