<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <!-- ================================================================= -->
    <!-- VENDOR BILL FORM: Email creation info -->
    <!-- ================================================================= -->
    <record id="view_move_form_fusion_accounts" model="ir.ui.view">
        <field name="name">account.move.form.fusion.accounts</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_move_form"/>
        <field name="priority">80</field>
        <field name="arch" type="xml">
            <!-- Add email creation badge -->
            <xpath expr="//div[hasclass('oe_title')]" position="before">
                <field name="x_fa_created_from_email" invisible="1"/>
                <div class="float-end" invisible="not x_fa_created_from_email or move_type != 'in_invoice'">
                    <span class="badge text-bg-info">
                        <i class="fa fa-envelope me-1"/>Created from Email
                    </span>
                    <field name="x_fa_ai_extracted" invisible="1"/>
                    <span class="badge text-bg-primary ms-1" invisible="not x_fa_ai_extracted">
                        <i class="fa fa-magic me-1"/>AI Extracted
                    </span>
                </div>
            </xpath>

            <!-- Add email origin info in notebook -->
            <xpath expr="//notebook" position="inside">
                <field name="x_fa_created_from_email" invisible="1"/>
                <page string="Email Origin" name="fa_email_origin"
                      invisible="not x_fa_created_from_email or move_type != 'in_invoice'">
                    <group>
                        <group string="Email Details">
                            <field name="x_fa_original_sender" readonly="1"/>
                            <field name="x_fa_match_level" widget="badge" readonly="1"/>
                        </group>
                        <group string="Processing">
                            <field name="x_fa_ai_extracted" readonly="1"/>
                        </group>
                    </group>
                </page>
            </xpath>
        </field>
    </record>

    <!-- ================================================================= -->
    <!-- VENDOR BILL SEARCH: Add email filter -->
    <!-- ================================================================= -->
    <record id="view_move_search_fusion_accounts" model="ir.ui.view">
        <field name="name">account.move.search.fusion.accounts</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_account_invoice_filter"/>
        <field name="priority">80</field>
        <field name="arch" type="xml">
            <xpath expr="//search" position="inside">
                <separator/>
                <filter string="From Email" name="from_email"
                        domain="[('x_fa_created_from_email', '=', True)]"/>
                <filter string="AI Extracted" name="ai_extracted"
                        domain="[('x_fa_ai_extracted', '=', True)]"/>
            </xpath>
        </field>
    </record>
</odoo>
