package de.ivu.elect.jee.faces;

import java.util.HashMap;
import java.util.Map;

public class HttpHeaderContentSecurityPolicyContent {

  private final Map<String, String> additionalPolicies;

  public HttpHeaderContentSecurityPolicyContent(Map<String, String> additionalPolicies) {
    this.additionalPolicies = additionalPolicies;
  }

  public HttpHeaderContentSecurityPolicyContent(String policy, String add) {
    Map<String, String> additionalPolicies = new HashMap<>(1);
    additionalPolicies.put(policy, add);
    this.additionalPolicies = additionalPolicies;
  }

  public HttpHeaderContentSecurityPolicyContent(HttpHeaderContentSecurityPolicy httpHeaderContentSecurityPolicy) {
    this(httpHeaderContentSecurityPolicy.policy(), httpHeaderContentSecurityPolicy.add());
  }

  public HttpHeaderContentSecurityPolicyContent(HttpHeaderContentSecurityPolicies httpHeaderContentSecurityPolicies) {
    Map<String, String> additionalPolicies = new HashMap<>(httpHeaderContentSecurityPolicies.value().length);
    for (HttpHeaderContentSecurityPolicy httpHeaderContentSecurityPolicy : httpHeaderContentSecurityPolicies.value()) {
      additionalPolicies.put(httpHeaderContentSecurityPolicy.policy(), httpHeaderContentSecurityPolicy.add());
    }
    this.additionalPolicies = additionalPolicies;
  }

  public Map<String, String> getAdditionalPolicies() {
    return additionalPolicies;
  }

  @Override
  public String toString() {
    return "HttpHeaderContentSecurityPolicyContent{" +
        "additionalPolicies='" + additionalPolicies + '\'' +
        '}';
  }
}
