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

    <!-- Form View (used as dialog from provider form) -->
    <record id="view_api_key_form" model="ir.ui.view">
        <field name="name">fusion.api.key.form</field>
        <field name="model">fusion.api.key</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button name="action_validate" type="object"
                            string="Validate Key" class="btn-primary"
                            icon="fa-check-circle"/>
                </header>
                <sheet>
                    <group>
                        <group>
                            <field name="name" placeholder="e.g. Production Key"/>
                            <field name="api_key" password="True" placeholder="Enter your API key"/>
                            <field name="environment"/>
                            <field name="is_default"/>
                            <field name="is_active"/>
                        </group>
                        <group>
                            <field name="provider_id" invisible="context.get('default_provider_id')"/>
                            <field name="provider_type" invisible="1"/>
                            <field name="validation_status" widget="badge"
                                   decoration-success="validation_status == 'valid'"
                                   decoration-danger="validation_status == 'invalid'"
                                   decoration-muted="validation_status == 'unknown'"/>
                            <field name="last_validated_at"/>
                            <field name="company_id" groups="base.group_multi_company"/>
                        </group>
                    </group>
                    <group string="OAuth Credentials"
                           invisible="provider_type not in ('google_oauth', 'microsoft_oauth')">
                        <group>
                            <field name="client_id" password="True"/>
                            <field name="client_secret" password="True"/>
                            <field name="redirect_uri"/>
                        </group>
                        <group>
                            <field name="access_token" password="True"/>
                            <field name="refresh_token" password="True"/>
                            <field name="token_expiry"/>
                        </group>
                    </group>
                    <field name="notes" placeholder="Optional notes about this key..."/>
                </sheet>
            </form>
        </field>
    </record>

</odoo>
