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 = "http://localhost:5000/sanksi";
		if (query != null) {
			const { ptId, noSanksi, keberatan, jawaban, banding, active, cabutSanksi, docPerbaikan } = 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`);
			parseURL.push(`active=${active || "true"}`);
			url += parseURL.join("&");
		}

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