package automaticmocking;

import authentication.AuthenticationService;
import authentication.Strength;
import interfacemanualmocking.DirectoryInterface;
import interfacemanualmocking.StrengthEstimationServiceInterface;

public class AuthenticationByPasswordService implements AuthenticationService {
    private interfacemanualmocking.DirectoryInterface directory;



    private interfacemanualmocking.StrengthEstimationServiceInterface strengthEstimationService;

    public void setStrengthEstimationService(interfacemanualmocking.StrengthEstimationServiceInterface strengthEstimationService) {
        this.strengthEstimationService = strengthEstimationService;
    }

    public AuthenticationByPasswordService(interfacemanualmocking.DirectoryInterface directory, StrengthEstimationServiceInterface strengthEstimationService) {
        this.directory = directory;
        this.strengthEstimationService = strengthEstimationService;
    }


    @Override
    public boolean isAMatch(String identifier, String autenthicationData) {
        String match = directory.getMatch(identifier);
        return match.equals(autenthicationData);
    }

    @Override
    public Strength dataStrenth(String autenthicationData) {
        int datasize = autenthicationData.length();
        int alphabetSize = 142;
        int strength = strengthEstimationService.equivalentBitLength(alphabetSize,datasize);

        Strength result = null ;
        if( strength >= 0 && strength <= 49 ) {
            result = Strength.VERY_WEAK;
        }
        else if ( strength >= 50 && strength <= 79 ) {
            result = Strength.WEAK;
        }
        else if ( strength >= 80 && strength <= 99 ) {
            result = Strength.REGULAR;
        }
        else if ( strength >= 100 ) {
            result = Strength.STRONG;
        }
        return result;
    }
    public void setDirectory(DirectoryInterface directory) {
        this.directory = directory;
    }


}


    //private StrengthEstimationServiceInterface dataStrenth(String autenthicationData) {
     //   int alphabetSize = 0;
       // int datasize = autenthicationData.length();
        //return strengthEstimationService.equivalentBitLength(alphabetSize, datasize);
    //}