import os
from typing import TYPE_CHECKING

import boto3

if TYPE_CHECKING:
    from mypy_boto3_cognito_idp.client import CognitoIdentityProviderClient
    from mypy_boto3_dynamodb.client import DynamoDBClient
    from mypy_boto3_s3 import S3Client
else:
    CognitoIdentityProviderClient = object
    DynamoDBClient = object
    S3Client = object


def get_dynamodb_client():
    running_sam_local = os.getenv('AWS_SAM_LOCAL')

    if os.getenv('AWS_LAMBDA_FUNCTION_NAME') and not running_sam_local:
        return boto3.client('dynamodb')

    docker_host = 'host.docker.internal'
    local_host = '127.0.0.1'
    host = docker_host if running_sam_local else local_host

    return boto3.client('dynamodb', endpoint_url=f'http://{host}:8000')


s3_client: S3Client = boto3.client('s3')
dynamodb_client: DynamoDBClient = get_dynamodb_client()
idp_client: CognitoIdentityProviderClient = boto3.client('cognito-idp')
