<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Form View for Configuration -->
    <record id="view_product_template_parameter_config_form" model="ir.ui.view">
        <field name="name">product.template.parameter.config.form</field>
        <field name="model">product.template.parameter</field>
        <field name="arch" type="xml">
            <form string="Configuración de Parámetro en Análisis">
                <sheet>
                    <group>
                        <group string="Análisis">
                            <field name="product_tmpl_id" 
                                   readonly="1"
                                   options="{'no_open': True}"/>
                        </group>
                        <group string="Parámetro">
                            <field name="parameter_id" 
                                   readonly="1"
                                   options="{'no_open': True}"/>
                            <field name="parameter_code"/>
                            <field name="parameter_value_type"/>
                            <field name="parameter_unit" invisible="parameter_value_type != 'numeric'"/>
                        </group>
                    </group>
                    <group string="Configuración">
                        <group>
                            <field name="sequence"/>
                            <field name="required"/>
                        </group>
                        <group>
                            <field name="instructions" widget="text"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- List View for Configuration -->
    <record id="view_product_template_parameter_config_list" model="ir.ui.view">
        <field name="name">product.template.parameter.config.list</field>
        <field name="model">product.template.parameter</field>
        <field name="arch" type="xml">
            <list string="Configuración de Parámetros por Análisis">
                <field name="product_tmpl_id"/>
                <field name="parameter_id"/>
                <field name="parameter_code"/>
                <field name="parameter_value_type"/>
                <field name="parameter_unit" optional="show"/>
                <field name="sequence"/>
                <field name="required"/>
            </list>
        </field>
    </record>

    <!-- Search View -->
    <record id="view_product_template_parameter_config_search" model="ir.ui.view">
        <field name="name">product.template.parameter.config.search</field>
        <field name="model">product.template.parameter</field>
        <field name="arch" type="xml">
            <search string="Buscar Configuración">
                <field name="product_tmpl_id" string="Análisis"/>
                <field name="parameter_id" string="Parámetro"/>
                <field name="parameter_code"/>
                <field name="parameter_name"/>
                <filter string="Requeridos" name="required" 
                        domain="[('required', '=', True)]"/>
                <filter string="Opcionales" name="optional" 
                        domain="[('required', '=', False)]"/>
                <separator/>
                <filter string="Numéricos" name="numeric" 
                        domain="[('parameter_value_type', '=', 'numeric')]"/>
                <filter string="Texto" name="text" 
                        domain="[('parameter_value_type', '=', 'text')]"/>
                <filter string="Sí/No" name="boolean" 
                        domain="[('parameter_value_type', '=', 'boolean')]"/>
                <filter string="Selección" name="selection" 
                        domain="[('parameter_value_type', '=', 'selection')]"/>
                <group expand="0" string="Agrupar por">
                    <filter string="Análisis" name="group_analysis" 
                            context="{'group_by': 'product_tmpl_id'}"/>
                    <filter string="Parámetro" name="group_parameter" 
                            context="{'group_by': 'parameter_id'}"/>
                    <filter string="Tipo de Valor" name="group_value_type" 
                            context="{'group_by': 'parameter_value_type'}"/>
                    <filter string="Requerido" name="group_required" 
                            context="{'group_by': 'required'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Pivot View for Analysis -->
    <record id="view_product_template_parameter_pivot" model="ir.ui.view">
        <field name="name">product.template.parameter.pivot</field>
        <field name="model">product.template.parameter</field>
        <field name="arch" type="xml">
            <pivot string="Matriz de Parámetros por Análisis">
                <field name="product_tmpl_id" type="row"/>
                <field name="parameter_id" type="col"/>
                <field name="required" type="measure"/>
            </pivot>
        </field>
    </record>

    <!-- Action -->
    <record id="action_product_template_parameter_config" model="ir.actions.act_window">
        <field name="name">Configuración Parámetros-Análisis</field>
        <field name="res_model">product.template.parameter</field>
        <field name="view_mode">list,form,pivot</field>
        <field name="search_view_id" ref="view_product_template_parameter_config_search"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Configurar parámetros en análisis
            </p>
            <p>
                Esta vista muestra la configuración de qué parámetros 
                están incluidos en cada análisis clínico.
            </p>
        </field>
    </record>
</odoo>