from src.infrastructure.vision_service import VertexVisionService
from src.infrastructure.repository import MongoPalmOilRepository
from src.domain.models import PalmOilBunch

class AnalyzeBunchUseCase:
    def __init__(self, vision_service: VertexVisionService, repo: MongoPalmOilRepository):
        self.vision_service = vision_service
        self.repo = repo

    def execute(self, image_path: str, yolo_result: dict):
        # 1. Get the visual fingerprint
        vector = self.vision_service.get_image_embedding(image_path)

        # 2. Create the Domain Entity
        bunch = PalmOilBunch(
            ripeness_class=yolo_result['class'],
            confidence=yolo_result['confidence'],
            embedding=vector,
            box=yolo_result['box']
        )

        # 3. Persist to "Memory"
        record_id = self.repo.save(bunch)
        return record_id
