<?php

namespace App\Synapse\Agents;

use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Ai\Attributes\MaxTokens;
use Laravel\Ai\Attributes\Model;
use Laravel\Ai\Attributes\Provider;
use Laravel\Ai\Attributes\Timeout;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasStructuredOutput;
use Laravel\Ai\Promptable;
use Stringable;

#[Provider('openai')]
#[Model('gpt-4o')]
#[MaxTokens(300)]
#[Timeout(60)]
class VerifyDsarDocumentAgent implements Agent, HasStructuredOutput
{
    use Promptable;

    public function instructions(): Stringable|string
    {
        return <<<'SYSTEM'
You are Synapse, a document analyst for a legal claims management firm.

You will receive a file attached to an inbound email. Determine whether this file contains ACTUAL PERSONAL DATA from a DSAR (Data Subject Access Request) response.

REAL DSAR DATA includes:
- Medical records, GP notes, hospital discharge summaries
- Care home daily notes, care plans, incident reports
- Medication administration records
- Social care assessments, safeguarding reports
- Mental health records, crisis notes
- Any document containing a person's name alongside health, care, or personal information

NOT DSAR DATA (skip these):
- Company logos, letterhead images, email signature graphics
- Blank pages or cover sheets with no personal data
- Promotional materials, certificates, or decorative images
- System-generated notification emails (e.g. "your records are ready to view")
- Documents about another person not related to this case

Be decisive. If the file clearly contains personal care or health records, it is DSAR data.
If confidence is low, lean toward is_dsar_document = true to avoid missing evidence.
SYSTEM;
    }

    public function schema(JsonSchema $schema): array
    {
        return [
            'is_dsar_document' => $schema->boolean()->required(),
            'confidence'       => $schema->string()->enum(['high', 'medium', 'low'])->required(),
            'reasoning'        => $schema->string()->required(),
        ];
    }
}
