from pydantic import Field
from turms.processors.base import Processor, ProcessorConfig
from turms.config import GeneratorConfig


class DisclaimerProcessorConfig(ProcessorConfig):
    type: str = "turms.processors.black.DisclaimerProcessor"
    disclaimer: str = '''""" This file was code generated by turms. If you want to change the contents of this file, you should make sure to add the MergeProcessor to your config will keep your changes when you re-run turms)."""
    '''


class DisclaimerProcessor(Processor):
    """A processor that uses black to format the generated python code

    Black is a code formatter that is used to enforce a consistent style on the generated python code.
    It needs to be seperately installed via 'pip install black'.
    """

    config: DisclaimerProcessorConfig = Field(default_factory=DisclaimerProcessorConfig)

    def run(self, gen_file: str, config: GeneratorConfig):
        return self.config.disclaimer + "\n" + gen_file
