import { post, get } from "../config/request";

export const createSanksi = async ({ number, ptId }, data) => {
	try {
		const res = await post(`/sanksi/create?number=${number}&ptId=${ptId}`, data);
		console.log(res);
		return res.data;
	} catch (error) {
		console.log("error", error);
		return false;
	}
};

export const getSanksi = async (query = {}) => {
	try {
		let url = "/sanksi";
		if (query != null) {
			const { ptId, noSanksi, keberatan, jawaban, banding, active, cabutSanksi, docPerbaikan, role, orgId } = query;
			url += "?";
			const parseURL = [];
			if (noSanksi) parseURL.push(`noSanksi=${noSanksi}`);
			if (ptId) parseURL.push(`ptId=${ptId}`);
			if (keberatan) parseURL.push(`keberatan=true`);
			if (banding) parseURL.push(`banding=true`);
			if (cabutSanksi) parseURL.push(`cabutSanksi=true`);
			if (docPerbaikan) parseURL.push(`docPerbaikan=true`);
			if (jawaban) parseURL.push(`jawaban=true`);
			if (role) {
				parseURL.push(`role=${role}`);
				if (role === "lldikti" && orgId) parseURL.push(`orgId=${orgId}`);
			}
			parseURL.push(`active=${active || "true"}`);
			url += parseURL.join("&");
		}

		const res = await get(url);
		return res.data;
	} catch (error) {
		console.log("error", error);
		return false;
	}
};
