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

    <!-- Usage List View -->
    <record id="view_ai_usage_list" model="ir.ui.view">
        <field name="name">fusion.clock.ai.usage.list</field>
        <field name="model">fusion.clock.ai.usage</field>
        <field name="arch" type="xml">
            <list string="AI Usage" default_order="date desc" create="false">
                <field name="date"/>
                <field name="feature"/>
                <field name="model_name"/>
                <field name="request_count" sum="Total Requests"/>
                <field name="prompt_tokens" sum="Total Prompt"/>
                <field name="completion_tokens" sum="Total Completion"/>
                <field name="total_tokens" sum="Total Tokens"/>
                <field name="estimated_cost_usd" sum="Total Cost" widget="monetary"
                       options="{'currency_id': False}"/>
            </list>
        </field>
    </record>

    <!-- Usage Search View -->
    <record id="view_ai_usage_search" model="ir.ui.view">
        <field name="name">fusion.clock.ai.usage.search</field>
        <field name="model">fusion.clock.ai.usage</field>
        <field name="arch" type="xml">
            <search string="Search Usage">
                <field name="feature"/>
                <field name="model_name"/>
                <filter name="today" string="Today"
                        domain="[('date', '=', context_today().strftime('%Y-%m-%d'))]"/>
                <filter name="this_week" string="This Week"
                        domain="[('date', '>=', (context_today() - datetime.timedelta(days=7)).strftime('%Y-%m-%d'))]"/>
                <filter name="this_month" string="This Month"
                        domain="[('date', '>=', context_today().strftime('%Y-%m-01'))]"/>
                <separator/>
                <filter name="group_date" string="Date"
                        context="{'group_by': 'date'}"/>
                <filter name="group_feature" string="Feature"
                        context="{'group_by': 'feature'}"/>
                <filter name="group_model" string="Model"
                        context="{'group_by': 'model_name'}"/>
            </search>
        </field>
    </record>

    <!-- Usage Graph View -->
    <record id="view_ai_usage_graph" model="ir.ui.view">
        <field name="name">fusion.clock.ai.usage.graph</field>
        <field name="model">fusion.clock.ai.usage</field>
        <field name="arch" type="xml">
            <graph string="AI Usage" type="line">
                <field name="date" interval="day"/>
                <field name="estimated_cost_usd" type="measure"/>
            </graph>
        </field>
    </record>

    <!-- Usage Pivot View -->
    <record id="view_ai_usage_pivot" model="ir.ui.view">
        <field name="name">fusion.clock.ai.usage.pivot</field>
        <field name="model">fusion.clock.ai.usage</field>
        <field name="arch" type="xml">
            <pivot string="AI Usage">
                <field name="date" interval="week" type="row"/>
                <field name="feature" type="col"/>
                <field name="total_tokens" type="measure"/>
                <field name="estimated_cost_usd" type="measure"/>
                <field name="request_count" type="measure"/>
            </pivot>
        </field>
    </record>

    <!-- Usage Action -->
    <record id="action_ai_usage" model="ir.actions.act_window">
        <field name="name">Usage Dashboard</field>
        <field name="res_model">fusion.clock.ai.usage</field>
        <field name="view_mode">graph,pivot,list</field>
        <field name="search_view_id" ref="view_ai_usage_search"/>
        <field name="context">{'search_default_this_month': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No AI usage recorded yet
            </p>
            <p>
                Usage statistics are tracked automatically when AI features are used.
            </p>
        </field>
    </record>

</odoo>
