from typing import Optional
from uuid import UUID

from app.core.module_framework.cqrs import ICommand, ICommandHandler
from app.core.module_framework.decorators import transactional, log_execution
from app.core.postgres.base_pkg.base_client import BasePostgresClient
from app.modules.dossier.domain.entities import DossierRecord
from app.modules.dossier.infrastructure.repositories import DossierRepository

class CreateDossierCommand(ICommand):
    project_id: UUID
    title: str
    document_type: str
    file_path: str

class CreateDossierCommandHandler(ICommandHandler[CreateDossierCommand, UUID]):
    def __init__(self, postgres_client: BasePostgresClient):
        self._postgres_client = postgres_client

    @log_execution
    @transactional
    def handle(self, command: CreateDossierCommand) -> UUID:
        repo = DossierRepository(self._conn)
        
        record = DossierRecord(
            project_id=command.project_id,
            title=command.title,
            document_type=command.document_type,
            file_path=command.file_path
        )
        
        repo.save(record)
        return record.id
