<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright 2024-2026 Nexa Systems Inc.
    License OPL-1 (Odoo Proprietary License v1.0)
    Part of the Fusion Claim Assistant product family.
-->
<odoo>
    <!-- Add Contact Type + ODSP fields to Partner Form -->
    <record id="view_partner_form_fusion_claims" model="ir.ui.view">
        <field name="name">res.partner.form.fusion.claims</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
            <!-- Our Contact Type field above the address -->
            <xpath expr="//span[@name='address_name']" position="before">
                <field name="x_fc_contact_type" placeholder="Select contact type..."/>
            </xpath>

            <!-- ADP Applications smart button for authorizers -->
            <xpath expr="//div[@name='button_box']" position="inside">
                <button name="action_view_adp_applications" type="object"
                        class="oe_stat_button" icon="fa-file-text"
                        invisible="x_fc_adp_application_count == 0">
                    <field name="x_fc_adp_application_count" widget="statinfo" string="Applications"/>
                </button>
            </xpath>

            <!-- Authorizer number for OTs/PTs/authorizer contacts -->
            <xpath expr="//field[@name='x_fc_contact_type']" position="after">
                <field name="x_fc_authorizer_number" string="ADP Reg. Number"
                       invisible="x_fc_contact_type not in ('occupational_therapist', 'physiotherapist', 'adp_agent')"
                       placeholder="e.g. 3000001234"/>
            </xpath>

            <!-- ODSP section in notebook -->
            <xpath expr="//notebook" position="inside">
                <page string="ODSP" name="odsp_info"
                      invisible="x_fc_contact_type not in ('odsp_customer', 'adp_odsp_customer', 'odsp_agent', 'odsp_office')">
                    <group string="ODSP Information">
                        <group>
                            <field name="x_fc_odsp_member_id"
                                   invisible="x_fc_contact_type == 'odsp_office'"/>
                            <field name="x_fc_case_worker_id"
                                   invisible="x_fc_contact_type == 'odsp_office'"/>
                        </group>
                        <group>
                            <field name="x_fc_date_of_birth"
                                   invisible="x_fc_contact_type == 'odsp_office'"/>
                            <field name="x_fc_healthcard_number"
                                   invisible="x_fc_contact_type == 'odsp_office'"/>
                        </group>
                    </group>
                    <group string="ODSP Office Details"
                           invisible="x_fc_contact_type != 'odsp_office'">
                        <group>
                            <field name="x_fc_is_odsp_office" invisible="1"/>
                            <field name="email" string="Office Email"/>
                            <field name="phone" string="Office Phone"/>
                        </group>
                    </group>
                </page>
            </xpath>
        </field>
    </record>

    <!-- Add Contact Type to list view -->
    <record id="view_partner_tree_fusion_claims" model="ir.ui.view">
        <field name="name">res.partner.tree.fusion.claims</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_tree"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='phone']" position="after">
                <field name="x_fc_contact_type" optional="hide"/>
            </xpath>
        </field>
    </record>

    <!-- Add Contact Type to search view -->
    <record id="view_partner_search_fusion_claims" model="ir.ui.view">
        <field name="name">res.partner.search.fusion.claims</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_res_partner_filter"/>
        <field name="arch" type="xml">
            <xpath expr="//filter[@name='type_company']" position="after">
                <separator/>
                <filter name="filter_odsp_customer" string="ODSP Customers"
                        domain="[('x_fc_contact_type', 'in', ['odsp_customer', 'adp_odsp_customer'])]"/>
                <filter name="filter_odsp_office" string="ODSP Offices"
                        domain="[('x_fc_contact_type', '=', 'odsp_office')]"/>
            </xpath>
        </field>
    </record>
</odoo>
