<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- List View for Rejection Reasons -->
    <record id="view_lims_rejection_reason_list" model="ir.ui.view">
        <field name="name">lims.rejection.reason.list</field>
        <field name="model">lims.rejection.reason</field>
        <field name="arch" type="xml">
            <list string="Motivos de Rechazo" editable="bottom">
                <field name="sequence" widget="handle"/>
                <field name="code"/>
                <field name="name"/>
                <field name="severity" widget="badge"/>
                <field name="requires_new_sample"/>
                <field name="rejection_count"/>
                <field name="active" widget="boolean_toggle"/>
            </list>
        </field>
    </record>

    <!-- Form View for Rejection Reasons -->
    <record id="view_lims_rejection_reason_form" model="ir.ui.view">
        <field name="name">lims.rejection.reason.form</field>
        <field name="model">lims.rejection.reason</field>
        <field name="arch" type="xml">
            <form string="Motivo de Rechazo">
                <sheet>
                    <widget name="web_ribbon" title="Archivado" invisible="active"/>
                    <div class="oe_title">
                        <label for="name"/>
                        <h1>
                            <field name="name" placeholder="Motivo de rechazo..."/>
                        </h1>
                    </div>
                    <group>
                        <group>
                            <field name="code"/>
                            <field name="severity"/>
                            <field name="sequence"/>
                        </group>
                        <group>
                            <field name="requires_new_sample"/>
                            <field name="active"/>
                            <field name="rejection_count"/>
                        </group>
                    </group>
                    <group string="Descripción">
                        <field name="description" nolabel="1" placeholder="Descripción detallada del motivo..."/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Search View for Rejection Reasons -->
    <record id="view_lims_rejection_reason_search" model="ir.ui.view">
        <field name="name">lims.rejection.reason.search</field>
        <field name="model">lims.rejection.reason</field>
        <field name="arch" type="xml">
            <search string="Buscar Motivos de Rechazo">
                <field name="name"/>
                <field name="code"/>
                <filter string="Activos" name="active" domain="[('active', '=', True)]"/>
                <filter string="Archivados" name="inactive" domain="[('active', '=', False)]"/>
                <separator/>
                <filter string="Requiere Nueva Muestra" name="requires_new" domain="[('requires_new_sample', '=', True)]"/>
                <separator/>
                <filter string="Severidad Alta/Crítica" name="high_severity" domain="[('severity', 'in', ['high', 'critical'])]"/>
                <group expand="0" string="Agrupar por">
                    <filter string="Severidad" name="group_severity" context="{'group_by': 'severity'}"/>
                    <filter string="Requiere Nueva Muestra" name="group_requires_new" context="{'group_by': 'requires_new_sample'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Action for Rejection Reasons -->
    <record id="action_lims_rejection_reason" model="ir.actions.act_window">
        <field name="name">Motivos de Rechazo</field>
        <field name="res_model">lims.rejection.reason</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="view_lims_rejection_reason_search"/>
        <field name="context">{'search_default_active': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Configure los motivos de rechazo de muestras
            </p>
            <p>
                Los motivos de rechazo permiten categorizar y documentar
                las razones por las cuales una muestra no puede ser procesada.
            </p>
        </field>
    </record>
</odoo>