# config/config.py
import json
import os

class Config:
    def __init__(self, config_file='config.json'):
        self.config_file = config_file
        self.config = self._load_config()

    def _load_config(self):
        if not os.path.exists(self.config_file):
            default_config = {
                'input_dir': '.',
                'output_dir': '.',
                'cronologia_file': 'cronologia.md',
                'attachments_dir': 'adjuntos'
            }
            self._save_config(default_config)
            return default_config
        
        with open(self.config_file, 'r', encoding='utf-8') as f:
            return json.load(f)

    def _save_config(self, config):
        with open(self.config_file, 'w', encoding='utf-8') as f:
            json.dump(config, f, indent=4)

    def get_input_dir(self):
        return self.config.get('input_dir', '.')

    def get_output_dir(self):
        return self.config.get('output_dir', '.')

    def get_cronologia_file(self):
        return os.path.join(
            self.get_output_dir(), 
            self.config.get('cronologia_file', 'cronologia.md')
        )

    def get_attachments_dir(self):
        return os.path.join(
            self.get_output_dir(),
            self.config.get('attachments_dir', 'adjuntos')
        )