import os
from typing import TYPE_CHECKING

import boto3

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


def get_dynamodb_client() -> DynamoDBClient:
    if os.getenv('AWS_LAMBDA_FUNCTION_NAME'):
        return boto3.client('dynamodb')

    # Use the Docker network address when running in a container
    host = 'host.docker.internal' if os.getenv('AWS_SAM_LOCAL') else '127.0.0.1'
    return boto3.client('dynamodb', endpoint_url=f'http://{host}:8000')


s3_client: S3Client = boto3.client('s3')
dynamodb_client: DynamoDBClient = get_dynamodb_client()
