package info.bukova.isspst;

import info.bukova.isspst.data.TripBillApproval;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Pepa Rokos
 */
public class TripBillAprovalUrlResolver implements EntityUrlResolver {

	@Autowired
	private HttpServletRequest request;

	@Override
	public String entityUrl(Object entity) {
		String defUrl = request.getRequestURL().toString();
		defUrl = defUrl.substring(0, defUrl.indexOf(request.getServletPath()));

		if (entity instanceof TripBillApproval) {
			String url = Constants.URL_MAP.get(entity.getClass());

			return defUrl + url + "?select=" + String.valueOf(((TripBillApproval)entity).getId());
		}

		return defUrl + "/app";
	}
}
