"""
Configuration des dossiers traités - GMAO Collège
"""
from datetime import datetime, timezone
from app_new.extensions import db


class ProcessedFolderConfig(db.Model):
    """Configuration des dossiers 'Traités' pour Outlook et ENT."""
    __tablename__ = "processed_folder_config"
    
    id = db.Column(db.Integer, primary_key=True)
    
    # Dossier Outlook
    outlook_folder_id = db.Column(db.Text, nullable=True)
    outlook_folder_name = db.Column(db.String(100), nullable=True)
    
    # Dossier ENT
    ent_folder_id = db.Column(db.String(100), nullable=True)
    ent_folder_name = db.Column(db.String(100), nullable=True)
    
    # Métadonnées
    created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc))
    updated_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))
    
    @classmethod
    def get_config(cls):
        """Récupère ou crée la configuration."""
        config = cls.query.first()
        if not config:
            config = cls()
            db.session.add(config)
            db.session.commit()
        return config
    
    def get(self, key, default=None):
        """Methode get pour compatibilite template dict-like."""
        return getattr(self, key, default)
    
    def __repr__(self):
        return f"<ProcessedFolderConfig outlook={self.outlook_folder_name} ent={self.ent_folder_name}>"