package com.dji.sample.manage.service.password;

import com.dji.sample.manage.model.password.PasswordRule;
import com.dji.sample.manage.model.password.PasswordRuleContext;
import com.dji.sample.manage.model.password.PasswordRuleResult;

/**
 * Rule 1 – Minimum length.
 * Password must be at least {@value #MIN_LENGTH} characters long.
 */
public class MinLengthPasswordRule implements PasswordRule {

    public static final int MIN_LENGTH = 8;

    @Override
    public PasswordRuleResult validate(String password, PasswordRuleContext context) {
        if (password == null || password.length() < MIN_LENGTH) {
            return PasswordRuleResult.fail(
                    "Password must be at least " + MIN_LENGTH + " characters long");
        }
        return PasswordRuleResult.ok();
    }

    @Override
    public String getRuleName() {
        return "MinLength";
    }

}
