import boto3

from src.aws.aws_api_client import AWSAPIClient
from src.system_var import environment


class CognitoClient(AWSAPIClient):
    def __init__(self) -> None:
        self.__client = boto3.client('cognito-idp')

    def login_by_user_password_flow(self, username: str, password: str, secret_hash: str):

        auth_response = self.__client.admin_initiate_auth(
            UserPoolId=environment.COGNITO_USER_POOL_ID,
            ClientId=environment.COGNITO_CLIENT_ID,
            AuthFlow='ADMIN_USER_PASSWORD_AUTH',
            AuthParameters={
                'USERNAME': username,
                'PASSWORD': password,
                'SECRET_HASH': secret_hash
            },
        )
        authentication_result = auth_response['AuthenticationResult']

        return authentication_result['IdToken'], authentication_result['RefreshToken'],
