// handle "GET /no-auth/asset-info" request to get asset info for this API server (contents of api-server.info)

'use strict';

const RestfulRequest = require(process.env.CSSVC_BACKEND_ROOT + '/api_server/lib/util/restful/restful_request');
const GetAssetInfo = require(process.env.CSSVC_BACKEND_ROOT + '/shared/server_utils/get_asset_data');
const ApiConfig = require(process.env.CSSVC_BACKEND_ROOT + '/api_server/config/config');

class AssetInfoRequest extends RestfulRequest {

	async authorize () {
		// no authorization required
	}

	// process the request...
	async process () {
		// return the asset info
		this.responseData = await GetAssetInfo({ serviceRoot: process.env.CSSVC_BACKEND_ROOT + '/api_server' });
		this.responseData.runTimeEnvironment = ApiConfig.getPreferredConfig().sharedGeneral.runTimeEnvironment;
	}

	// describe this route for help
	static describe () {
		return {
			tag: 'asset-info',
			summary: 'Get asset and build information',
			access: 'No access rule',
			description: 'Asset information is generated by the automated build process. It contains version, build, asset names and MD5 hashes of all assets associated with with the running version. In development, this will be null.',
			returns: {
				summary: 'Returns an object containing the contents of the api-server.info file.',
				looksLike: {
					assetInfo: '<asset-info>'
				}
			}
		};
	}
}

module.exports = AssetInfoRequest;
