package org.sagebionetworks.bridge.models.studies;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * The policies that govern password creation. New studies will be created with the default password 
 * policy, which requires 8 characters, one numeric, one symbol and one upper- and lower-case 
 * character. However, this policy can be adjusted for legacy studies which were created with much 
 * more lax constraints.
 */
public final class PasswordPolicy {
    
    /**
     * Currently 100 is the maximum password length allowed by Stormpath.
     */
    public static final int FIXED_MAX_LENGTH = 100;
    public static final int VALUE_OFF = 0;
    public static final int VALUE_ON = 1;
    
    /**
     * The password policy that is initially created for a study.
     */
    public static final PasswordPolicy DEFAULT_PASSWORD_POLICY = new PasswordPolicy(8, true, true, true);
    
    private final int minLength;
    private final boolean numericRequired;
    private final boolean symbolRequired;
    private final boolean upperCaseRequired;
    
    @JsonCreator
    public PasswordPolicy(@JsonProperty("minLength") int minLength,
                    @JsonProperty("numericRequired") boolean requireNumeric,
                    @JsonProperty("symbolRequired") boolean requireSymbol,
                    @JsonProperty("UpperCaseRequired") boolean requireUpperCase) {
        this.minLength = minLength;
        this.numericRequired = requireNumeric;
        this.symbolRequired = requireSymbol;
        this.upperCaseRequired = requireUpperCase;
    }
    
    public int getMinLength() {
        return minLength;
    }
    public boolean isNumericRequired() {
        return numericRequired;
    }
    public boolean isSymbolRequired() {
        return symbolRequired;
    }
    public boolean isUpperCaseRequired() {
        return upperCaseRequired;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + Objects.hashCode(minLength);
        result = prime * result + Objects.hashCode(numericRequired);
        result = prime * result + Objects.hashCode(symbolRequired);
        result = prime * result + Objects.hashCode(upperCaseRequired);
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null || getClass() != obj.getClass())
            return false;
        PasswordPolicy other = (PasswordPolicy) obj;
        return (Objects.equals(minLength, other.minLength) && 
                Objects.equals(numericRequired, other.numericRequired) &&
                Objects.equals(symbolRequired, other.symbolRequired) &&
                Objects.equals(upperCaseRequired, other.upperCaseRequired));
    }

    @Override
    public String toString() {
        return String.format("PasswordPolicy [minLength=%s, numericRequired=%s, symbolRequired=%s, upperCaseRequired=%s]",
            minLength, numericRequired, symbolRequired, upperCaseRequired);
    }
     
    
}

@@ -555,98 +555,8 @@
    %0A
-    /**%0A     * Currently 100 is the maximum password length allowed by Stormpath.%0A     */%0A
     
@@ -602,11 +602,11 @@
 H = 
-100
+999
 ;%0A  

Changing max length to 999