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

    <!-- ===== Tree View ===== -->
    <record id="woo_product_map_view_tree" model="ir.ui.view">
        <field name="name">woo.product.map.tree</field>
        <field name="model">woo.product.map</field>
        <field name="arch" type="xml">
            <tree>
                <field name="instance_id"/>
                <field name="product_id"/>
                <field name="woo_product_name"/>
                <field name="woo_sku"/>
                <field name="woo_product_type"/>
                <field name="sync_price"/>
                <field name="sync_inventory"/>
                <field name="last_synced"/>
                <field name="state" widget="badge"
                       decoration-success="state == 'mapped'"
                       decoration-warning="state == 'conflict'"
                       decoration-danger="state == 'error'"/>
            </tree>
        </field>
    </record>

    <!-- ===== Form View ===== -->
    <record id="woo_product_map_view_form" model="ir.ui.view">
        <field name="name">woo.product.map.form</field>
        <field name="model">woo.product.map</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <group>
                        <group string="Odoo">
                            <field name="instance_id"/>
                            <field name="product_id"/>
                            <field name="company_id" groups="base.group_multi_company"/>
                        </group>
                        <group string="WooCommerce">
                            <field name="woo_product_id"/>
                            <field name="woo_product_name"/>
                            <field name="woo_sku"/>
                            <field name="woo_product_type"/>
                            <field name="woo_parent_id"/>
                            <field name="is_variation"/>
                        </group>
                    </group>
                    <group>
                        <group string="Sync Options">
                            <field name="sync_price"/>
                            <field name="sync_inventory"/>
                            <field name="sync_images"/>
                        </group>
                        <group string="Status">
                            <field name="state"/>
                            <field name="last_synced"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- ===== Search View ===== -->
    <record id="woo_product_map_view_search" model="ir.ui.view">
        <field name="name">woo.product.map.search</field>
        <field name="model">woo.product.map</field>
        <field name="arch" type="xml">
            <search>
                <field name="product_id"/>
                <field name="woo_product_name"/>
                <field name="woo_sku"/>
                <filter name="mapped" string="Mapped"
                        domain="[('state', '=', 'mapped')]"/>
                <filter name="unmapped" string="Unmapped"
                        domain="[('state', '=', 'unmapped')]"/>
                <filter name="conflict" string="Conflicts"
                        domain="[('state', '=', 'conflict')]"/>
                <filter name="error" string="Errors"
                        domain="[('state', '=', 'error')]"/>
                <group expand="1" string="Group By">
                    <filter name="group_instance" string="Instance"
                            context="{'group_by': 'instance_id'}"/>
                    <filter name="group_state" string="State"
                            context="{'group_by': 'state'}"/>
                    <filter name="group_type" string="Product Type"
                            context="{'group_by': 'woo_product_type'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- ===== Action ===== -->
    <record id="action_woo_product_map" model="ir.actions.act_window">
        <field name="name">Product Mapping</field>
        <field name="res_model">woo.product.map</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="woo_product_map_view_search"/>
    </record>

</odoo>
