<commit_before>var path = require("path");

exports.putInRoot = true;

exports.makeCombinedAPI = function (apis, sourceDir, apiOutputDir) {
	console.log("Generating Haxe combined SDK to " + apiOutputDir);
	
	copyTree(path.resolve(sourceDir, "source"), apiOutputDir);
	
	for (var i in apis) {
		makeDatatypes(apis[i], sourceDir, apiOutputDir);
		makeAPI(apis[i], sourceDir, apiOutputDir);
	}
	
	generateSimpleFiles(apis, sourceDir, apiOutputDir);
}

function makeDatatypes(api, sourceDir, apiOutputDir) {
	var templateDir = path.resolve(sourceDir, "templates");
	
	var modelTemplate = ejs.compile(readFile(path.resolve(templateDir, "Model.hx.ejs")));
	var enumTemplate = ejs.compile(readFile(path.resolve(templateDir, "Enum.hx.ejs")));
	
	for (var d in api.datatypes) {
		var datatype = api.datatypes[d];
		
		var modelLocals = {};
		modelLocals.api = api;
		modelLocals.datatype = datatype;
		modelLocals.getPropertyDef = getModelPropertyDef;
		var generatedModel = null;
		
		if (datatype.isenum) {
			generatedModel = enumTemplate(modelLocals);
		}
		else {
			modelLocals.needsPlayFabUtil = needsPlayFabUtil(datatype);
			generatedModel = modelTemplate(modelLocals);
		}
		
		writeFile(path.resolve(apiOutputDir, "com/playfab/" + api.name.toLowerCase() + "models/" + datatype.name + ".hx"), generatedModel);
	}
}

function needsPlayFabUtil(datatype) {
	for (var i in datatype.properties) {
		var property = datatype.properties[i];
		if (property.actualtype === "DateTime")
			return true;
	}
	
	return false;
}

function makeAPI(api, sourceDir, apiOutputDir) {
	console.log("Generating Haxe " + api.name + " library to " + apiOutputDir);
	
	var templateDir = path.resolve(sourceDir, "templates");
	
	var apiTemplate = ejs.compile(readFile(path.resolve(templateDir, "API.hx.ejs")));
	var apiLocals = {};
	apiLocals.api = api;
	apiLocals.getAuthParams = getAuthParams;
	apiLocals.getRequestActions = getRequestActions;
	apiLocals.getResultActions = getResultActions;
	apiLocals.getUrlAccessor = getUrlAccessor;
	apiLocals.hasClientOptions = api.name === "Client";
	var generatedApi = apiTemplate(apiLocals);
	writeFile(path.resolve(apiOutputDir, "com/playfab/PlayFab" + api.name + "API.hx"), generatedApi);
}

function generateSimpleFiles(apis, sourceDir, apiOutputDir) {
	var errorsTemplate = ejs.compile(readFile(path.resolve(sourceDir, "templates/Errors.hx.ejs")));
	var errorLocals = {};
	errorLocals.errorList = apis[0].errorList;
	errorLocals.errors = apis[0].errors;
	var generatedErrors = errorsTemplate(errorLocals);
	writeFile(path.resolve(apiOutputDir, "com/playfab/PlayFabError.hx"), generatedErrors);
	
	var versionTemplate = ejs.compile(readFile(path.resolve(sourceDir, "templates/PlayFabVersion.hx.ejs")));
	var versionLocals = {};
	versionLocals.sdkRevision = exports.sdkVersion;
	var generatedVersion = versionTemplate(versionLocals);
	writeFile(path.resolve(apiOutputDir, "com/playfab/PlayFabVersion.hx"), generatedVersion);

	var settingsTemplate = ejs.compile(readFile(path.resolve(sourceDir, "templates/PlayFabSettings.hx.ejs")));
	var settingsLocals = {};
	settingsLocals.hasServerOptions = false;
	settingsLocals.hasClientOptions = false;
	for (var i in apis) {
		if (apis[i].name === "Client")
			settingsLocals.hasClientOptions = true;
		else
			settingsLocals.hasServerOptions = true;
	}
	var generatedsettings = settingsTemplate(settingsLocals);
	writeFile(path.resolve(apiOutputDir, "com/playfab/PlayFabSettings.hx"), generatedsettings);
}

function getModelPropertyDef(property, datatype) {
	var type = getPropertyASType(property, datatype);
	
	if (property.collection) {
		if (property.collection === "array") {
			type = "Array<" + type + ">";
		}
		else if (property.collection === "map") {
			type = "Dynamic";
		}
		else {
			throw "Unknown collection type: " + property.collection + " for " + property.name + " in " + datatype.name;
		}
	}
	
	var prefix = "var ";
	if (property.optional)
		prefix = "@:optional var ";
	
	return prefix + property.name + ":" + type + ";";
}

function getPropertyASType(property, datatype) {
	if (property.actualtype === "String")
		return "String";
	else if (property.actualtype === "Boolean")
		return "Bool";
	else if (property.actualtype === "int16")
		return "Int";
	else if (property.actualtype === "uint16")
		return "UInt";
	else if (property.actualtype === "int32")
		return "Int";
	else if (property.actualtype === "uint32")<commit_msg>Include comments in "model" classes.<commit_after>var path = require("path");

exports.putInRoot = true;

exports.makeCombinedAPI = function (apis, sourceDir, apiOutputDir) {
	console.log("Generating Haxe combined SDK to " + apiOutputDir);
	
	copyTree(path.resolve(sourceDir, "source"), apiOutputDir);
	
	for (var i in apis) {
		makeDatatypes(apis[i], sourceDir, apiOutputDir);
		makeAPI(apis[i], sourceDir, apiOutputDir);
	}
	
	generateSimpleFiles(apis, sourceDir, apiOutputDir);
}

function makeDatatypes(api, sourceDir, apiOutputDir) {
	var templateDir = path.resolve(sourceDir, "templates");
	
	var modelTemplate = ejs.compile(readFile(path.resolve(templateDir, "Model.hx.ejs")));
	var enumTemplate = ejs.compile(readFile(path.resolve(templateDir, "Enum.hx.ejs")));
	
	for (var d in api.datatypes) {
		var datatype = api.datatypes[d];
		
		var modelLocals = {};
		modelLocals.api = api;
		modelLocals.datatype = datatype;
		modelLocals.getPropertyDef = getModelPropertyDef;
		var generatedModel = null;
		
		if (datatype.isenum) {
			generatedModel = enumTemplate(modelLocals);
		}
		else {
			modelLocals.needsPlayFabUtil = needsPlayFabUtil(datatype);
			generatedModel = modelTemplate(modelLocals);
		}
		
		writeFile(path.resolve(apiOutputDir, "com/playfab/" + api.name.toLowerCase() + "models/" + datatype.name + ".hx"), generatedModel);
	}
}

function needsPlayFabUtil(datatype) {
	for (var i in datatype.properties) {
		var property = datatype.properties[i];
		if (property.actualtype === "DateTime")
			return true;
	}
	
	return false;
}

function makeAPI(api, sourceDir, apiOutputDir) {
	console.log("Generating Haxe " + api.name + " library to " + apiOutputDir);
	
	var templateDir = path.resolve(sourceDir, "templates");
	
	var apiTemplate = ejs.compile(readFile(path.resolve(templateDir, "API.hx.ejs")));
	var apiLocals = {};
	apiLocals.api = api;
	apiLocals.getAuthParams = getAuthParams;
	apiLocals.getRequestActions = getRequestActions;
	apiLocals.getResultActions = getResultActions;
	apiLocals.getUrlAccessor = getUrlAccessor;
	apiLocals.hasClientOptions = api.name === "Client";
	var generatedApi = apiTemplate(apiLocals);
	writeFile(path.resolve(apiOutputDir, "com/playfab/PlayFab" + api.name + "API.hx"), generatedApi);
}

function generateSimpleFiles(apis, sourceDir, apiOutputDir) {
	var errorsTemplate = ejs.compile(readFile(path.resolve(sourceDir, "templates/Errors.hx.ejs")));
	var errorLocals = {};
	errorLocals.errorList = apis[0].errorList;
	errorLocals.errors = apis[0].errors;
	var generatedErrors = errorsTemplate(errorLocals);
	writeFile(path.resolve(apiOutputDir, "com/playfab/PlayFabError.hx"), generatedErrors);
	
	var versionTemplate = ejs.compile(readFile(path.resolve(sourceDir, "templates/PlayFabVersion.hx.ejs")));
	var versionLocals = {};
	versionLocals.sdkRevision = exports.sdkVersion;
	var generatedVersion = versionTemplate(versionLocals);
	writeFile(path.resolve(apiOutputDir, "com/playfab/PlayFabVersion.hx"), generatedVersion);

	var settingsTemplate = ejs.compile(readFile(path.resolve(sourceDir, "templates/PlayFabSettings.hx.ejs")));
	var settingsLocals = {};
	settingsLocals.hasServerOptions = false;
	settingsLocals.hasClientOptions = false;
	for (var i in apis) {
		if (apis[i].name === "Client")
			settingsLocals.hasClientOptions = true;
		else
			settingsLocals.hasServerOptions = true;
	}
	var generatedsettings = settingsTemplate(settingsLocals);
	writeFile(path.resolve(apiOutputDir, "com/playfab/PlayFabSettings.hx"), generatedsettings);
}

function getModelPropertyDef(property, datatype) {
	var type = getPropertyASType(property, datatype);
	
	if (property.collection) {
		if (property.collection === "array") {
			type = "Array<" + type + ">";
		}
		else if (property.collection === "map") {
			type = "Dynamic";
		}
		else {
			throw "Unknown collection type: " + property.collection + " for " + property.name + " in " + datatype.name;
		}
	}
	
	var prefix = "var ";
	if (property.optional)
		prefix = "@:optional var ";
	
	var comment = "";
	if (property.description) {
		comment = "/**";
		var lineLength = 80;
		var line = "";
		for (var i = 0; i < property.description.length; i += line.length + 1) {
			line = property.description.substr(i, lineLength);
			if (line.length == lineLength)
				line = line.substr(0, line.lastIndexOf(" "));
			comment += "\n\t * " + line;
		}
		comment += "\n\t */\n\t";
	}
	
	return comment + prefix + property.name + ":" + type + ";";
}

function getPropertyASType(property, datatype) {
	if (property.actualtype === "String")
		return "String";
	else if (property.actualtype === "Boolean")
		return "Bool";
	else if (property.actualtype === "int16")
		return "Int";
	else if (property.actualtype === "uint16")
		return "UInt";
	else if (property.actualtype === "int32")
		return "Int";
	else if (property.actualtype === "uint32")
{'fraction_non_alphanumeric': 0.14067906574394465, 'fraction_numerical': 0.0027032871972318337, 'mean_word_length': 5.121111846459298, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2717829', 'n_tokens_mistral': 3205, 'n_tokens_neox': 3015, 'n_words': 606}