<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <!-- Extend VoIP Provider form to add RingCentral credentials and Provision button -->
    <record id="voip_provider_view_form_inherit_rc" model="ir.ui.view">
        <field name="name">voip.provider.form.inherit.ringcentral</field>
        <field name="model">voip.provider</field>
        <field name="inherit_id" ref="voip.voip_provider_view_form"/>
        <field name="arch" type="xml">
            <xpath expr="//sheet" position="inside">
                <separator string="RingCentral Integration"/>
                <group>
                    <group>
                        <field name="rc_client_id" placeholder="Client ID from RingCentral Developer Console"/>
                        <field name="rc_client_secret" password="True"
                               placeholder="Client Secret"/>
                    </group>
                    <group>
                        <field name="rc_jwt_token" password="True"
                               placeholder="JWT Token from RingCentral Credentials"/>
                        <field name="rc_server_url"
                               placeholder="https://platform.ringcentral.com"/>
                    </group>
                </group>
                <group invisible="not rc_device_id">
                    <group>
                        <field name="rc_device_id"/>
                    </group>
                    <group>
                        <div class="text-muted small">
                            Find this device in RingCentral Admin Portal under
                            Phones &amp; Devices to configure its outbound Caller ID.
                        </div>
                    </group>
                </group>
                <div class="mt-2 mb-4">
                    <button name="action_provision_sip" type="object"
                            string="Provision SIP Credentials"
                            class="btn-primary"
                            icon="fa-plug"
                            confirm="This will fetch SIP credentials from RingCentral and auto-configure the provider and your user settings. Continue?"/>
                    <span class="text-muted ms-3">
                        Fetches WSS endpoint, SIP domain, username, password, and authorization ID from RingCentral.
                    </span>
                </div>
            </xpath>
        </field>
    </record>

    <!-- Override list view: remove editable so clicking opens form view -->
    <record id="voip_provider_list_inherit_rc" model="ir.ui.view">
        <field name="name">voip.provider.list.inherit.ringcentral</field>
        <field name="model">voip.provider</field>
        <field name="inherit_id" ref="voip.voip_provider_tree_view"/>
        <field name="arch" type="xml">
            <xpath expr="//list" position="attributes">
                <attribute name="editable"/>
            </xpath>
            <xpath expr="//field[@name='mode']" position="after">
                <field name="rc_client_id" optional="hide" string="RC Client ID"/>
            </xpath>
        </field>
    </record>

</odoo>
