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

    <!-- Tree View -->
    <record id="view_api_consumer_tree" model="ir.ui.view">
        <field name="name">fusion.api.consumer.tree</field>
        <field name="model">fusion.api.consumer</field>
        <field name="arch" type="xml">
            <list>
                <field name="name"/>
                <field name="technical_name"/>
                <field name="module_state" widget="badge"
                       decoration-success="module_state == 'installed'"
                       decoration-muted="module_state != 'installed'"
                       optional="show"/>
                <field name="is_active" widget="boolean_toggle"/>
                <field name="auto_detected"/>
                <field name="first_seen_at" optional="hide"/>
                <field name="total_month_cost" string="Month Cost ($)"/>
                <field name="total_month_requests" string="Month Requests"/>
            </list>
        </field>
    </record>

    <!-- Form View -->
    <record id="view_api_consumer_form" model="ir.ui.view">
        <field name="name">fusion.api.consumer.form</field>
        <field name="model">fusion.api.consumer</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="action_toggle_access" type="object"
                                class="oe_stat_button"
                                icon="fa-power-off">
                            <field name="is_active" widget="boolean_button"
                                   options='{"terminology": {"string_true": "Active", "string_false": "Disabled"}}'/>
                        </button>
                    </div>
                    <div class="oe_title">
                        <h1><field name="name"/></h1>
                    </div>
                    <group>
                        <group>
                            <field name="technical_name"/>
                            <field name="module_id"/>
                            <field name="module_state"/>
                        </group>
                        <group>
                            <field name="auto_detected"/>
                            <field name="first_seen_at"/>
                            <field name="total_month_cost"/>
                            <field name="total_month_requests"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Access Rules" name="access">
                            <field name="access_ids">
                                <list editable="bottom">
                                    <field name="provider_id"/>
                                    <field name="is_enabled"/>
                                    <field name="monthly_budget_usd"/>
                                    <field name="daily_budget_usd"/>
                                    <field name="max_rpm"/>
                                    <field name="max_rpd"/>
                                    <field name="current_month_cost" string="Month Spend"/>
                                    <field name="current_day_requests" string="Today"/>
                                    <field name="budget_usage_pct" widget="progressbar" string="Budget %"/>
                                </list>
                            </field>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Action -->
    <record id="action_api_consumer" model="ir.actions.act_window">
        <field name="name">Consumers</field>
        <field name="res_model">fusion.api.consumer</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No consumers detected yet
            </p>
            <p>Fusion modules will appear here automatically when they make their first API call.</p>
        </field>
    </record>

</odoo>
