<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- ================================================================= -->
    <!-- AI TOOLS: Server Actions for Client Data Queries (MUST BE FIRST)  -->
    <!-- ================================================================= -->

    <!-- Tool 1: Search Client Profiles -->
    <record id="ai_tool_search_clients" model="ir.actions.server">
        <field name="name">Fusion: Search Client Profiles</field>
        <field name="state">code</field>
        <field name="use_in_ai" eval="True"/>
        <field name="model_id" ref="ai.model_ai_agent"/>
        <field name="code">
ai['result'] = record._fc_tool_search_clients(search_term, city_filter, condition_filter)
        </field>
        <field name="ai_tool_description">Search for client profiles in Fusion Claims. Can search by name, health card number, city, or medical condition. Returns matching profiles with basic info and financial summaries.</field>
        <field name="ai_tool_schema">{"type": "object", "properties": {"search_term": {"type": "string", "description": "Search term to match against name, health card number, or city"}, "city_filter": {"type": "string", "description": "Filter by city name"}, "condition_filter": {"type": "string", "description": "Filter by medical condition (e.g., CVA, diabetes)"}}, "required": []}</field>
    </record>

    <!-- Tool 2: Get Client Details -->
    <record id="ai_tool_client_details" model="ir.actions.server">
        <field name="name">Fusion: Get Client Details</field>
        <field name="state">code</field>
        <field name="use_in_ai" eval="True"/>
        <field name="model_id" ref="ai.model_ai_agent"/>
        <field name="code">
ai['result'] = record._fc_tool_client_details(profile_id)
        </field>
        <field name="ai_tool_description">Get detailed information about a specific client profile including personal info, medical status, benefits, claims history, and ADP application history. Requires profile_id from a previous search.</field>
        <field name="ai_tool_schema">{"type": "object", "properties": {"profile_id": {"type": "number", "description": "ID of the client profile to get details for"}}, "required": ["profile_id"]}</field>
    </record>

    <!-- Tool 3: Get Aggregated Stats -->
    <record id="ai_tool_client_stats" model="ir.actions.server">
        <field name="name">Fusion: Get Claims Statistics</field>
        <field name="state">code</field>
        <field name="use_in_ai" eval="True"/>
        <field name="model_id" ref="ai.model_ai_agent"/>
        <field name="code">
ai['result'] = record._fc_tool_claims_stats()
        </field>
        <field name="ai_tool_description">Get aggregated statistics about Fusion Claims data: total profiles, total orders, breakdown by sale type, breakdown by workflow status, and top cities by client count. No parameters needed.</field>
        <field name="ai_tool_schema">{"type": "object", "properties": {}, "required": []}</field>
    </record>

    <!-- ================================================================= -->
    <!-- AI TOPIC (references tools above)                                 -->
    <!-- ================================================================= -->
    <record id="ai_topic_client_intelligence" model="ai.topic">
        <field name="name">Fusion Claims Client Intelligence</field>
        <field name="description">Query client profiles, ADP claims, funding history, medical conditions, and device information.</field>
        <field name="instructions">You help users find information about ADP clients, claims, medical conditions, devices, and funding history. Use the Fusion search/details/stats tools to query data.</field>
        <field name="tool_ids" eval="[(6, 0, [
            ref('fusion_claims.ai_tool_search_clients'),
            ref('fusion_claims.ai_tool_client_details'),
            ref('fusion_claims.ai_tool_client_stats'),
        ])]"/>
    </record>

    <!-- ================================================================= -->
    <!-- AI AGENT (references topic above)                                 -->
    <!-- ================================================================= -->
    <record id="ai_agent_fusion_claims" model="ai.agent">
        <field name="name">Fusion Claims Intelligence</field>
        <field name="subtitle">Ask about clients, ADP claims, funding history, medical conditions, and devices.</field>
        <field name="llm_model">gpt-4.1</field>
        <field name="response_style">analytical</field>
        <field name="restrict_to_sources" eval="False"/>
        <field name="system_prompt">You are Fusion Claims Intelligence, an AI assistant for ADP claims management.

You help staff find information about clients, medical conditions, mobility devices, funding history, and claim status.

Capabilities:
1. Search client profiles by name, health card number, city, or medical condition
2. Get detailed client information including claims history and ADP applications
3. Provide aggregated statistics about claims, funding types, and demographics

Response guidelines:
- Be concise and data-driven
- Format monetary values with $ and commas
- Include key identifiers (name, health card, city) when listing clients
- Include order number, status, and amounts when discussing claims
- If asked about a specific client, search first, then get details
- Always provide the profile ID for record lookup

Key terminology:
- ADP = Assistive Devices Program (Ontario government)
- Client Type REG = Regular (75% ADP / 25% Client), ODS/OWP/ACS = 100% ADP
- Sale Types: ADP, ODSP, WSIB, Insurance, March of Dimes, Muscular Dystrophy, Hardship Funding
- Sections: 2a = Walkers, 2b = Manual Wheelchairs, 2c = Power Bases/Scooters, 2d = Seating</field>
        <field name="topic_ids" eval="[(6, 0, [ref('ai_topic_client_intelligence')])]"/>
    </record>
</odoo>
