<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <!-- ================================================================= -->
    <!-- ACTIVITY LOG - LIST VIEW -->
    <!-- ================================================================= -->
    <record id="view_fusion_accounts_log_list" model="ir.ui.view">
        <field name="name">fusion.accounts.log.list</field>
        <field name="model">fusion.accounts.log</field>
        <field name="arch" type="xml">
            <list string="Email Processing Log" create="0" edit="0"
                  decoration-success="action_taken == 'bill_created'"
                  decoration-warning="action_taken == 'blocked'"
                  decoration-danger="action_taken == 'failed'"
                  decoration-muted="action_taken == 'no_vendor'">
                <header>
                    <button name="action_block_vendor" type="object"
                            string="Block Vendor" class="btn-secondary"
                            icon="fa-ban"/>
                    <button name="action_enable_vendor" type="object"
                            string="Enable Vendor" class="btn-secondary"
                            icon="fa-check"/>
                </header>
                <field name="create_date" string="Date"/>
                <field name="email_from"/>
                <field name="email_subject"/>
                <field name="vendor_id"/>
                <field name="match_level" widget="badge"
                       decoration-info="match_level == 'exact_email'"
                       decoration-success="match_level == 'domain'"
                       decoration-warning="match_level == 'name'"
                       decoration-danger="match_level == 'no_match'"/>
                <field name="action_taken" widget="badge"
                       decoration-success="action_taken == 'bill_created'"
                       decoration-warning="action_taken == 'blocked'"
                       decoration-danger="action_taken == 'failed'"/>
                <field name="bill_id"/>
                <field name="ai_extracted" widget="boolean"/>
                <field name="vendor_blocked" string="Blocked" widget="boolean"/>
            </list>
        </field>
    </record>

    <!-- ================================================================= -->
    <!-- ACTIVITY LOG - FORM VIEW -->
    <!-- ================================================================= -->
    <record id="view_fusion_accounts_log_form" model="ir.ui.view">
        <field name="name">fusion.accounts.log.form</field>
        <field name="model">fusion.accounts.log</field>
        <field name="arch" type="xml">
            <form string="Email Processing Log" create="0" edit="0">
                <header>
                    <button name="action_block_vendor" type="object"
                            string="Block Vendor" class="btn-secondary"
                            icon="fa-ban"
                            invisible="not vendor_id or vendor_blocked"/>
                    <button name="action_enable_vendor" type="object"
                            string="Enable Vendor" class="btn-secondary"
                            icon="fa-check"
                            invisible="not vendor_id or not vendor_blocked"/>
                </header>
                <sheet>
                    <div class="oe_title">
                        <h1><field name="email_subject" readonly="1"/></h1>
                    </div>
                    <group>
                        <group string="Email Details">
                            <field name="email_from"/>
                            <field name="email_date"/>
                            <field name="create_date" string="Processed At"/>
                        </group>
                        <group string="Processing Result">
                            <field name="vendor_id"/>
                            <field name="vendor_blocked" string="Vendor Blocked"/>
                            <field name="match_level" widget="badge"/>
                            <field name="action_taken" widget="badge"/>
                            <field name="bill_id"/>
                            <field name="ai_extracted"/>
                        </group>
                    </group>
                    <group string="AI Extraction Result" invisible="not ai_extracted">
                        <field name="ai_result" widget="text" nolabel="1" colspan="2"/>
                    </group>
                    <group string="Notes" invisible="not notes">
                        <field name="notes" nolabel="1" colspan="2"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- ================================================================= -->
    <!-- ACTIVITY LOG - SEARCH VIEW -->
    <!-- ================================================================= -->
    <record id="view_fusion_accounts_log_search" model="ir.ui.view">
        <field name="name">fusion.accounts.log.search</field>
        <field name="model">fusion.accounts.log</field>
        <field name="arch" type="xml">
            <search string="Activity Log">
                <field name="email_from"/>
                <field name="email_subject"/>
                <field name="vendor_id"/>
                <separator/>
                <!-- Action Filters -->
                <filter string="Bills Created" name="bill_created" domain="[('action_taken', '=', 'bill_created')]"/>
                <filter string="Blocked" name="blocked" domain="[('action_taken', '=', 'blocked')]"/>
                <filter string="Failed" name="failed" domain="[('action_taken', '=', 'failed')]"/>
                <separator/>
                <filter string="AI Extracted" name="ai_extracted" domain="[('ai_extracted', '=', True)]"/>
                <separator/>
                <!-- Time Period Filter (Odoo date filter with period selector) -->
                <filter string="Date" name="filter_date" date="create_date"/>
                <separator/>
                <!-- Match Level Filters -->
                <filter string="Exact Email Match" name="exact" domain="[('match_level', '=', 'exact_email')]"/>
                <filter string="Domain Match" name="domain_match" domain="[('match_level', '=', 'domain')]"/>
                <filter string="Name Match" name="name_match" domain="[('match_level', '=', 'name')]"/>
                <filter string="No Match" name="no_match" domain="[('match_level', '=', 'no_match')]"/>
                <group>
                    <filter string="Action" name="group_action" context="{'group_by': 'action_taken'}"/>
                    <filter string="Match Level" name="group_match" context="{'group_by': 'match_level'}"/>
                    <filter string="Vendor" name="group_vendor" context="{'group_by': 'vendor_id'}"/>
                    <filter string="Day" name="group_day" context="{'group_by': 'create_date:day'}"/>
                    <filter string="Week" name="group_week" context="{'group_by': 'create_date:week'}"/>
                    <filter string="Month" name="group_month" context="{'group_by': 'create_date:month'}"/>
                    <filter string="Year" name="group_year" context="{'group_by': 'create_date:year'}"/>
                </group>
            </search>
        </field>
    </record>
</odoo>
