from aiva.triple_gate_validator import validator

# Patent Validation Skill (v1.0)
# Allows any Genesis Agent to evoke the 9-Patent Triple-Gate CNS.

class PatentValidationAgent:
    def __init__(self, blackboard=None):
        self.validator = validator
        self.blackboard = blackboard

    def execute_mission(self, content_to_validate, task_context, worker_id="swarm_agent"):
        """
        Validates content against the Triple-Gate (P1-P9).
        Logs findings to the blackboard if available.
        """
        print(f"🛡️ [GENESIS] Validating content for {worker_id}...")
        
        # Metadata required for Gate 1 (Foundation)
        metadata = {
            "worker_id": worker_id,
            "timestamp": "2026-01-07T05:22:00Z" # Current Context
        }
        
        # Execute Triple-Gate Validation
        report = self.validator.validate_worker_output(
            content_to_validate,
            task_context,
            worker_id,
            metadata
        )
        
        status = "✅ VALIDATED" if report['passed'] else "❌ FAILED"
        score = f"{report['overall_score']:.2%}"
        
        print(f"🛡️ [RESULT] {status} | Score: {score}")
        
        if self.blackboard:
            self.blackboard.log_event(
                "validation_event",
                {
                    "worker": worker_id,
                    "status": status,
                    "score": score,
                    "report": report
                }
            )
            
        return report

# Global skill instance
skill = PatentValidationAgent()
