import {UtilApplications} from "./UtilApplications.js";
import {Config} from "./Config.js";
import {DataConverter} from "./DataConverter.js";

class DataConverterDeity {
	/**
	 * @param deity
	 * @param [opts] Options object.
	 * @param [opts.isAddPermission]
	 */
	static getDeityJournal (deity, opts) {
		opts = opts || {};

		const content = DataConverter.getWithDescriptionPlugins(() => {
			return `<div>
				${Renderer.deity.getOrderedParts(deity, `<p>`, `</p>`)}
				${deity.entries ? `<div>${Renderer.get().setFirstSection(true).render({entries: deity.entries}, 1)}</div>` : ""}
			</div>`
		});

		const img = deity.symbolImg ? Renderer.utils.getMediaUrl(deity.symbolImg, "href", "img") : null;

		const out = {
			name: UtilApplications.getCleanEntityName(DataConverter.getNameWithSourcePart(deity, {displayName: deity.title ? `${deity.name}, ${deity.title.toTitleCase()}` : null})),
			permission: {default: 0},
			entryTime: Date.now(),
			content,
			img,
		};

		if (opts.isAddPermission) out.permission = {default: Config.get("importDeity", "permissions")};

		return out;
	}
}

export {DataConverterDeity};
