package org.kar.karideo;

public class CacheFilter {
	@Override
	public List<ResourceFilter> create(AbstractMethod am) {
	    if (am.isAnnotationPresent(CacheMaxAge.class)) {
	        CacheMaxAge maxAge = am.getAnnotation(CacheMaxAge.class);
	        return newCacheFilter("max-age: " + maxAge.unit().toSeconds(maxAge.time()));
	    } else if (am.isAnnotationPresent(NoCache.class)) {
	        return newCacheFilter("no-cache");
	    } else {
	        return Collections.emptyList();
	    }
	}

	private List<ResourceFilter> newCacheFilter(String content) {
	    return Collections
	            .<ResourceFilter> singletonList(new CacheResponseFilter(content));
	}
}
