package com.atlassian.stash.internal.web.soy.functions;

import com.atlassian.soy.renderer.JsExpression;

public class BaseAvatarFunction {
    protected static enum AvatarSize {
        //We fetch @2x size images for HiDPI displays
        XSMALL(16 * 2),
        SMALL(24 * 2),
        MEDIUM(32 * 2),
        LARGE(48 * 2),
        XLARGE(64 * 2),
        XXLARGE(96 * 2),
        XXXLARGE(128 * 2);

        private static final String JSON_MAP;

        static {
            final StringBuilder sb = new StringBuilder().append("({");
            String sep = "";
            for (AvatarSize size : AvatarSize.values()) {
                sb.append(sep).append(size.name()).append(':').append(size.size);
                sep = ",";
            }
            JSON_MAP = sb.append("})").toString();
        }

        final int size;

        AvatarSize(int size) {
            this.size = size;
        }
    }

    public static JsExpression selectSizeExpression(String size) {
        return new JsExpression(AvatarSize.JSON_MAP + "[" + size + ".toUpperCase()]");
    }
}
