/**
 * Copyright (c) 2000-2017 Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * pSubscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */

package com.liferay.portlet.sitesadmin.asset;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.model.Group;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.asset.model.BaseAssetRenderer;

import java.util.Locale;

import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

/**
 * @author Ricardo Couso
 */
public class SiteAssetRenderer extends BaseAssetRenderer {

	public SiteAssetRenderer(Group group) {
		if (group.isSite() || group.isStagingGroup()) {
			_siteGroup = group;
		}
		else {
			throw new IllegalArgumentException(
				"Only site groups are supported");
		}
	}

	@Override
	public String getClassName() {
		return Group.class.getName();
	}

	@Override
	public long getClassPK() { return _siteGroup.getPrimaryKey(); }

	@Override
	public long getGroupId() { return _siteGroup.getGroupId(); }

	@Override
	public String getSummary(
		PortletRequest portletRequest, PortletResponse portletResponse) {

		try {
			return _siteGroup.getDescriptiveName(
				PortalUtil.getLocale(portletRequest));
		}
		catch (Exception pe) {
			_log.error(
				"Unable to get summary for group " + _siteGroup.getGroupId(),
				pe);
		}

		return null;
	}

	@Override
	public String getTitle(Locale locale) {
		try {
			return _siteGroup.getDescriptiveName(locale);
		}
		catch (Exception pe) {
			_log.error(
				"Unable to get descriptive name for group " +
					_siteGroup.getGroupId(),
				pe);
		}

		return null;
	}

	@Override
	public long getUserId() {
		return _siteGroup.getCreatorUserId();
	}

	@Override
	public String getUserName() {
		return null;
	}

	@Override
	public String getUuid() {
		return _siteGroup.getUuid();
	}

	@Override
	public String render(
		RenderRequest renderRequest, RenderResponse renderResponse,
		String template)
	throws Exception {

		return null;
	}

	private static Log _log = LogFactoryUtil.getLog(SiteAssetRenderer.class);

	private Group _siteGroup;

}