<?php

namespace App\Ai\Agents;

use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasStructuredOutput;
use Laravel\Ai\Promptable;

class RedressScotlandEstimator implements Agent, HasStructuredOutput
{
    use Promptable;

    public function instructions(): string
    {
        return <<<TEXT
        You estimate likely Redress Scotland individually assessed payment levels.
        Return cautious estimates only. Do not provide legal advice.
        Consider all care-setting statements together.
        Consider whether relevant prior payments or serious criminal convictions may affect eligibility/payment.
        
        Use these payment bands:
        Level 1: £10,000 - £20,000
        Level 2: £20,000 - £40,000
        Level 3: £40,000 - £60,000
        Level 4: £60,000 - £80,000
        Level 5: £80,000 - £100,000

        Assess severity, frequency, duration, abuse type, humiliation, fear, targeting, institutional failure, and lasting impact
        TEXT;
    }

    public function schema(JsonSchema $schema): array
    {
        return [
            'level' => $schema->string()->enum([
                'Level 1',
                'Level 2',
                'Level 3',
                'Level 4',
                'Level 5',
            ])->required(),

            'value_min' => $schema->integer()->required(),
            'value_max' => $schema->integer()->required(),

            'confidence' => $schema->string()->enum([
                'Low',
                'Moderate',
                'High',
            ])->required(),

            'rationale' => $schema->string()->required(),

            'statement_results' => $schema->array()
                ->items($schema->object(fn ($schema) => [
                    'care_setting_id' => $schema->integer()->required(),
                    'level' => $schema->string()->required(),
                    'value_min' => $schema->integer()->required(),
                    'value_max' => $schema->integer()->required(),
                    'rationale' => $schema->string()->required(),
                ]))
                ->required(),
        ];
    }
}