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

    <!-- Tree View -->
    <record id="view_api_access_tree" model="ir.ui.view">
        <field name="name">fusion.api.access.tree</field>
        <field name="model">fusion.api.access</field>
        <field name="arch" type="xml">
            <list editable="bottom">
                <field name="consumer_id"/>
                <field name="provider_id"/>
                <field name="is_enabled" widget="boolean_toggle"/>
                <field name="monthly_budget_usd"/>
                <field name="daily_budget_usd" optional="hide"/>
                <field name="max_rpm"/>
                <field name="max_rpd" optional="hide"/>
                <field name="current_month_cost" string="Month Spend ($)"/>
                <field name="current_day_requests" string="Today Reqs"/>
                <field name="budget_usage_pct" widget="progressbar" string="Budget Used"/>
                <field name="is_budget_exceeded" column_invisible="True"/>
            </list>
        </field>
    </record>

    <!-- Form View -->
    <record id="view_api_access_form" model="ir.ui.view">
        <field name="name">fusion.api.access.form</field>
        <field name="model">fusion.api.access</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <group>
                        <group string="Link">
                            <field name="consumer_id"/>
                            <field name="provider_id"/>
                            <field name="is_enabled"/>
                        </group>
                        <group string="Current Usage">
                            <field name="current_month_cost"/>
                            <field name="current_day_cost"/>
                            <field name="current_day_requests"/>
                            <field name="budget_usage_pct" widget="progressbar"/>
                            <field name="is_budget_exceeded"/>
                        </group>
                    </group>
                    <group>
                        <group string="Budget Limits">
                            <field name="monthly_budget_usd"/>
                            <field name="daily_budget_usd"/>
                        </group>
                        <group string="Rate Limits">
                            <field name="max_rpm"/>
                            <field name="max_rpd"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Action -->
    <record id="action_api_access" model="ir.actions.act_window">
        <field name="name">Access Rules</field>
        <field name="res_model">fusion.api.access</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No access rules configured
            </p>
            <p>Access rules control which Fusion modules can use which API providers, with budget and rate limits.</p>
        </field>
    </record>

</odoo>
