import json
import logging
import os
from pg_streamline import Producer  # Importing the Producer class from the producer module


# Setting up basic logging configuration
logging.basicConfig(level=logging.INFO)


class PGWal2JSONPGOutputProducer(Producer):
    """
    PGOutputProducer class that extends the Producer class to handle specific types of messages.
    """

    def perform_action(self, plugin: str, message: dict):
        """
        Overriding the perform_action method to handle different types of messages.

        :param plugin: Name of the plugin that generated the message.
        :param message: Message generated by the plugin.
        """
        logging.info(f'plugin: {plugin}')
        parsed_message = json.loads(message.decode('utf-8'))
        logging.info(f'parsed_message: {json.dumps(parsed_message, indent=4)}')


if __name__ == '__main__':
    os.environ.setdefault('DB_PASSWORD', 'postgres')

    config_file_path = 'examples/wal2json/config.yaml'
    
    # Creating an instance of PGOutputProducer with a pool size of 5
    producer = PGWal2JSONPGOutputProducer(config_path=config_file_path)

    # Starting the replication process
    producer.start_replication(publication_names=['events'], protocol_version='4')
