<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- ===================================================================== -->
    <!-- Field Mapping Configuration Wizard Form View -->
    <!-- ===================================================================== -->
    <record id="view_field_mapping_config_wizard_form" model="ir.ui.view">
        <field name="name">fusion_claims.field_mapping_config.form</field>
        <field name="model">fusion_claims.field_mapping_config</field>
        <field name="arch" type="xml">
            <form string="Field Mapping Configuration">
                <header>
                    <button name="action_save_and_close" type="object" 
                            string="Save &amp; Close" class="btn-primary"/>
                    <button name="action_auto_detect" type="object" 
                            string="Auto-Detect Fields" class="btn-secondary"/>
                    <button name="action_reset_defaults" type="object" 
                            string="Reset to Defaults" class="btn-secondary"
                            confirm="This will reset all mappings to the default FC field names. Continue?"/>
                </header>
                <sheet>
                    <div class="oe_title">
                        <h1>Field Mapping Configuration</h1>
                    </div>
                    
                    <!-- Summary Section -->
                    <group>
                        <group>
                            <field name="total_mappings" readonly="1"/>
                            <field name="valid_mappings" readonly="1"/>
                        </group>
                        <group>
                            <field name="invalid_mappings" readonly="1" 
                                   decoration-danger="invalid_mappings > 0"/>
                        </group>
                    </group>
                    
                    <!-- Instructions -->
                    <div class="alert alert-info" role="alert">
                        <strong>How to Use:</strong>
                        <ul class="mb-0">
                            <li>Click <strong>Auto-Detect Fields</strong> to find existing custom fields</li>
                            <li>Edit the <strong>Field Name</strong> column to use any custom field</li>
                            <li>The <strong>Valid</strong> column shows if the field exists on the model</li>
                            <li>Click <strong>Save &amp; Close</strong> to apply your configuration</li>
                            <li>Use <strong>Reset to Defaults</strong> to restore default FC field names</li>
                        </ul>
                    </div>
                    
                    <!-- All Field Mappings in one list -->
                    <field name="mapping_ids" nolabel="1">
                        <list editable="bottom" create="false" delete="false"
                              decoration-danger="not field_exists and field_name">
                            <field name="model_name" readonly="1" string="Model"/>
                            <field name="label" readonly="1" string="Field"/>
                            <field name="field_name" string="Source Field Name"/>
                            <field name="default_fc_field" readonly="1" string="Default FC Field"/>
                            <field name="field_exists" widget="boolean" readonly="1" string="Valid"/>
                            <field name="config_param_key" column_invisible="1"/>
                            <field name="wizard_id" column_invisible="1"/>
                            <field name="sequence" column_invisible="1"/>
                        </list>
                    </field>
                    
                    <!-- Help Section -->
                    <div class="alert alert-secondary mt-3" role="alert">
                        <h5>Help</h5>
                        <ul class="mb-0">
                            <li><strong>Source Field Name</strong>: The custom field to read data from (e.g., x_fc_sale_type)</li>
                            <li><strong>Default FC Field</strong>: The standard Fusion Central field name</li>
                            <li><strong>Valid</strong>: Shows if the source field exists on the model</li>
                            <li>Auto-Detect will find existing custom fields and save them. Close and reopen to see results.</li>
                        </ul>
                    </div>
                </sheet>
                <footer>
                    <button name="action_save_and_close" type="object" 
                            string="Save &amp; Close" class="btn-primary"/>
                    <button name="action_save" type="object" 
                            string="Save" class="btn-secondary"/>
                    <button name="action_close" type="object" 
                            string="Cancel" class="btn-secondary"/>
                </footer>
            </form>
        </field>
    </record>
    
    <!-- ===================================================================== -->
    <!-- Action to open the wizard -->
    <!-- ===================================================================== -->
    <record id="action_field_mapping_config_wizard" model="ir.actions.act_window">
        <field name="name">Field Mapping Configuration</field>
        <field name="res_model">fusion_claims.field_mapping_config</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
        <field name="context">{}</field>
    </record>
</odoo>
