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

    <!-- ============================================================
         Configuration Flow — Tree View
         ============================================================ -->
    <record id="view_wc_config_flow_tree" model="ir.ui.view">
        <field name="name">fusion.wc.config.flow.tree</field>
        <field name="model">fusion.wc.config.flow</field>
        <field name="arch" type="xml">
            <list string="Configuration Flows">
                <field name="sequence" widget="handle"/>
                <field name="name"/>
                <field name="equipment_type"/>
                <field name="state" widget="badge"
                    decoration-success="state == 'active'"
                    decoration-info="state == 'draft'"
                    decoration-muted="state == 'archived'"/>
                <field name="step_count"/>
                <field name="node_count"/>
                <field name="connection_count"/>
            </list>
        </field>
    </record>

    <!-- ============================================================
         Configuration Flow — Form View
         ============================================================ -->
    <record id="view_wc_config_flow_form" model="ir.ui.view">
        <field name="name">fusion.wc.config.flow.form</field>
        <field name="model">fusion.wc.config.flow</field>
        <field name="arch" type="xml">
            <form string="Configuration Flow">
                <header>
                    <button name="action_open_designer" type="object"
                        string="Open Visual Designer"
                        class="btn-primary"
                        icon="fa-sitemap"/>
                    <button name="action_new_assessment_form" type="object"
                        string="New Assessment"
                        class="btn-secondary"
                        icon="fa-external-link"/>
                    <button name="action_activate" type="object"
                        string="Activate"
                        class="btn-success"
                        invisible="state == 'active'"/>
                    <button name="action_archive" type="object"
                        string="Archive"
                        invisible="state == 'archived'"/>
                    <button name="action_reset_draft" type="object"
                        string="Reset to Draft"
                        invisible="state == 'draft'"/>
                    <field name="state" widget="statusbar"
                        statusbar_visible="draft,active,archived"/>
                </header>
                <sheet>
                    <div class="oe_title">
                        <h1>
                            <field name="name" placeholder="e.g. Standard Manual Wheelchair Config"/>
                        </h1>
                    </div>
                    <group>
                        <group>
                            <field name="equipment_type"/>
                            <field name="sequence"/>
                            <field name="active" invisible="1"/>
                        </group>
                        <group>
                            <field name="step_count"/>
                            <field name="node_count"/>
                            <field name="connection_count"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Form Steps" name="form_steps">
                            <field name="step_ids">
                                <list editable="bottom">
                                    <field name="sequence" widget="handle"/>
                                    <field name="name"/>
                                    <field name="step_type"/>
                                    <field name="icon"/>
                                    <field name="section_code"/>
                                    <field name="is_required"/>
                                </list>
                            </field>
                            <div class="mt-2">
                                <button name="action_create_default_steps" type="object"
                                    string="Generate Default Steps"
                                    class="btn-secondary"
                                    icon="fa-magic"
                                    confirm="This will replace existing steps. Continue?"/>
                            </div>
                        </page>
                        <page string="Description" name="description">
                            <field name="description" placeholder="Describe this configuration flow..."/>
                        </page>
                        <page string="Nodes" name="nodes">
                            <field name="node_ids">
                                <list editable="bottom">
                                    <field name="sequence" widget="handle"/>
                                    <field name="name"/>
                                    <field name="node_type"/>
                                    <field name="section_id"/>
                                    <field name="decision_field"
                                        invisible="node_type != 'decision'"/>
                                    <field name="decision_operator"
                                        invisible="node_type != 'decision'"/>
                                    <field name="decision_value"
                                        invisible="node_type != 'decision'"/>
                                    <field name="action_type"
                                        invisible="node_type != 'action'"/>
                                    <field name="measurement_field"
                                        invisible="node_type != 'measurement_check'"/>
                                    <field name="comparison"
                                        invisible="node_type != 'measurement_check'"/>
                                    <field name="threshold_value"
                                        invisible="node_type != 'measurement_check'"/>
                                </list>
                            </field>
                        </page>
                        <page string="Connections" name="connections">
                            <field name="connection_ids">
                                <list editable="bottom">
                                    <field name="sequence" widget="handle"/>
                                    <field name="source_node_id"
                                        domain="[('flow_id', '=', parent.id)]"/>
                                    <field name="target_node_id"
                                        domain="[('flow_id', '=', parent.id)]"/>
                                    <field name="source_port"/>
                                    <field name="label"/>
                                </list>
                            </field>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <!-- ============================================================
         Configuration Flow — Action
         ============================================================ -->
    <record id="action_wc_config_flow" model="ir.actions.act_window">
        <field name="name">Configuration Flows</field>
        <field name="res_model">fusion.wc.config.flow</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create a Configuration Flow
            </p>
            <p>
                Configuration flows define visual decision trees that control
                which options are shown, hidden, or required during a wheelchair
                assessment. Use the Visual Designer to build flows graphically.
            </p>
        </field>
    </record>

</odoo>
