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

    <!-- ===== Tree View ===== -->
    <record id="woo_sync_log_view_tree" model="ir.ui.view">
        <field name="name">woo.sync.log.tree</field>
        <field name="model">woo.sync.log</field>
        <field name="arch" type="xml">
            <list create="0" edit="0" delete="0">
                <field name="create_date" string="Date"/>
                <field name="instance_id"/>
                <field name="sync_type"/>
                <field name="direction"/>
                <field name="record_ref"/>
                <field name="state" widget="badge"
                       decoration-success="state == 'success'"
                       decoration-danger="state == 'failed'"
                       decoration-warning="state == 'conflict'"/>
                <field name="message"/>
            </list>
        </field>
    </record>

    <!-- ===== Form View (read-only) ===== -->
    <record id="woo_sync_log_view_form" model="ir.ui.view">
        <field name="name">woo.sync.log.form</field>
        <field name="model">woo.sync.log</field>
        <field name="arch" type="xml">
            <form create="0" edit="0" delete="0">
                <sheet>
                    <group>
                        <group>
                            <field name="create_date"/>
                            <field name="instance_id"/>
                            <field name="sync_type"/>
                            <field name="direction"/>
                        </group>
                        <group>
                            <field name="record_ref"/>
                            <field name="state"/>
                            <field name="company_id" groups="base.group_multi_company"/>
                        </group>
                    </group>
                    <group string="Message">
                        <field name="message" nolabel="1"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- ===== Search View ===== -->
    <record id="woo_sync_log_view_search" model="ir.ui.view">
        <field name="name">woo.sync.log.search</field>
        <field name="model">woo.sync.log</field>
        <field name="arch" type="xml">
            <search>
                <field name="record_ref"/>
                <field name="message"/>
                <filter name="success" string="Success"
                        domain="[('state', '=', 'success')]"/>
                <filter name="failed" string="Failed"
                        domain="[('state', '=', 'failed')]"/>
                <filter name="conflict" string="Conflict"
                        domain="[('state', '=', 'conflict')]"/>
                <separator/>
                <filter name="today" string="Today"
                        domain="[('create_date', '&gt;=', (context_today()).strftime('%Y-%m-%d'))]"/>
                <separator/>
                <filter name="group_sync_type" string="Sync Type"
                        context="{'group_by': 'sync_type'}"/>
                <filter name="group_direction" string="Direction"
                        context="{'group_by': 'direction'}"/>
                <filter name="group_instance" string="Instance"
                        context="{'group_by': 'instance_id'}"/>
                <filter name="group_state" string="State"
                        context="{'group_by': 'state'}"/>
            </search>
        </field>
    </record>

    <!-- ===== Action ===== -->
    <record id="action_woo_sync_log" model="ir.actions.act_window">
        <field name="name">Sync Logs</field>
        <field name="res_model">woo.sync.log</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="woo_sync_log_view_search"/>
    </record>

</odoo>
