import logging
import os
from typing import Optional

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')


def migrate_data(source_path: str, destination_path: str) -> bool:
    """
    Migrates data from a source file to a destination file.

    Args:
        source_path: The path to the source file.
        destination_path: The path to the destination file.

    Returns:
        True if the migration was successful, False otherwise.
    """
    try:
        # Read data from source file
        with open(source_path, 'r') as source_file:
            data = source_file.readlines()

        # Transform data (example: convert to uppercase)
        transformed_data = [line.upper() for line in data]

        # Write data to destination file
        with open(destination_path, 'w') as destination_file:
            destination_file.writelines(transformed_data)

        logging.info(f"Data migrated successfully from {source_path} to {destination_path}")
        return True

    except FileNotFoundError:
        logging.error(f"File not found: {source_path} or {destination_path}")
        return False
    except Exception as e:
        logging.error(f"An error occurred during data migration: {e}")
        return False


if __name__ == '__main__':
    # Create sample data files if they don't exist
    script_dir = os.path.dirname(os.path.abspath(__file__))
    source_file_path = os.path.join(script_dir, 'source.txt')
    destination_file_path = os.path.join(script_dir, 'destination.txt')

    if not os.path.exists(source_file_path):
        with open(source_file_path, 'w') as f:
            f.write("This is a sample line.\n")
            f.write("Another sample line.\n")

    # Example usage:
    if migrate_data(source_file_path, destination_file_path):
        print("Data migration completed. Check destination.txt.")
    else:
        print("Data migration failed. Check logs.")