import { ServiceError } from "@grpc/grpc-js";
import { IronPdfServiceClient } from "../generated_proto/ironpdfengineproto/IronPdfService";
import { EmptyResultP__Output } from "../generated_proto/ironpdfengineproto/EmptyResultP";
import { handleEmptyResultP__Output } from "./util";

export async function setIsDebug(
	client: IronPdfServiceClient,
	isDebug: boolean
): Promise<void> {
	return new Promise(function (resolve, reject) {
		client.systemLoggerSetIsDebug(
			{ isDebug: isDebug },
			async (
				err: ServiceError | null,
				value: EmptyResultP__Output | undefined
			) => {
				if (err) {
					reject(err.name + err.message);
				} else if (value) {
					handleEmptyResultP__Output(value, reject);
					resolve();
				}
			}
		);
	});
}

export async function setLicenseKey(
	client: IronPdfServiceClient,
	licenseKey: string
): Promise<void> {
	return new Promise(function (resolve, reject) {
		client.systemLicenseSetLicenseKey(
			{ licenseKey: licenseKey },
			async (
				err: ServiceError | null,
				value: EmptyResultP__Output | undefined
			) => {
				if (err) {
					reject(err.name + err.message);
				} else {
					handleEmptyResultP__Output(value, reject);
					resolve();
				}
			}
		);
	});
}
