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

    <!-- ============================================================ -->
    <!--                      Question Views                          -->
    <!-- ============================================================ -->

    <record id="view_question_form" model="ir.ui.view">
        <field name="name">encoach.question.form</field>
        <field name="model">encoach.question</field>
        <field name="arch" type="xml">
            <form string="Question">
                <sheet>
                    <group>
                        <group string="Classification">
                            <field name="skill"/>
                            <field name="question_type"/>
                            <field name="difficulty"/>
                            <field name="status"/>
                        </group>
                        <group string="Taxonomy">
                            <field name="subject_id"/>
                            <field name="topic_id"/>
                            <field name="marks"/>
                            <field name="source_type"/>
                            <field name="source_id" invisible="not source_type"/>
                        </group>
                    </group>
                    <group string="Question Content">
                        <field name="stem" widget="text" placeholder="Enter the question stem..."/>
                    </group>
                    <group>
                        <group>
                            <field name="options" widget="text" placeholder='JSON array: ["A", "B", "C", "D"]'/>
                        </group>
                        <group>
                            <field name="correct_answer" widget="text"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="IRT Parameters" name="irt">
                            <group>
                                <group>
                                    <field name="irt_a" string="Discrimination (a)"/>
                                    <field name="irt_b" string="Difficulty (b)"/>
                                    <field name="irt_c" string="Guessing (c)"/>
                                </group>
                            </group>
                        </page>
                        <page string="Flags" name="flags">
                            <group>
                                <group>
                                    <field name="ai_generated"/>
                                    <field name="ielts_certified"/>
                                    <field name="format_validated"/>
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record id="view_question_list" model="ir.ui.view">
        <field name="name">encoach.question.list</field>
        <field name="model">encoach.question</field>
        <field name="arch" type="xml">
            <list string="Questions" decoration-muted="status == 'retired'" decoration-danger="status == 'flagged'">
                <field name="stem" string="Question" widget="char"/>
                <field name="skill"/>
                <field name="question_type"/>
                <field name="difficulty"/>
                <field name="status"/>
                <field name="marks"/>
            </list>
        </field>
    </record>

    <record id="view_question_search" model="ir.ui.view">
        <field name="name">encoach.question.search</field>
        <field name="model">encoach.question</field>
        <field name="arch" type="xml">
            <search string="Search Questions">
                <field name="stem"/>
                <field name="subject_id"/>
                <field name="topic_id"/>
                <separator/>
                <filter string="Listening" name="filter_listening" domain="[('skill', '=', 'listening')]"/>
                <filter string="Reading" name="filter_reading" domain="[('skill', '=', 'reading')]"/>
                <filter string="Writing" name="filter_writing" domain="[('skill', '=', 'writing')]"/>
                <filter string="Speaking" name="filter_speaking" domain="[('skill', '=', 'speaking')]"/>
                <filter string="Grammar" name="filter_grammar" domain="[('skill', '=', 'grammar')]"/>
                <filter string="Vocabulary" name="filter_vocabulary" domain="[('skill', '=', 'vocabulary')]"/>
                <separator/>
                <filter string="MCQ" name="filter_mcq" domain="[('question_type', '=', 'mcq')]"/>
                <filter string="Gap Fill" name="filter_gap_fill" domain="[('question_type', '=', 'gap_fill')]"/>
                <filter string="Matching" name="filter_matching" domain="[('question_type', '=', 'matching')]"/>
                <separator/>
                <filter string="Easy" name="filter_easy" domain="[('difficulty', '=', 'easy')]"/>
                <filter string="Medium" name="filter_medium" domain="[('difficulty', '=', 'medium')]"/>
                <filter string="Hard" name="filter_hard" domain="[('difficulty', '=', 'hard')]"/>
                <separator/>
                <filter string="Draft" name="filter_draft" domain="[('status', '=', 'draft')]"/>
                <filter string="Active" name="filter_active" domain="[('status', '=', 'active')]"/>
                <filter string="Flagged" name="filter_flagged" domain="[('status', '=', 'flagged')]"/>
                <filter string="Skill" name="group_skill" context="{'group_by': 'skill'}"/>
                <filter string="Type" name="group_type" context="{'group_by': 'question_type'}"/>
                <filter string="Difficulty" name="group_difficulty" context="{'group_by': 'difficulty'}"/>
                <filter string="Status" name="group_status" context="{'group_by': 'status'}"/>
                <filter string="Subject" name="group_subject" context="{'group_by': 'subject_id'}"/>
            </search>
        </field>
    </record>

    <record id="action_question" model="ir.actions.act_window">
        <field name="name">Question Bank</field>
        <field name="res_model">encoach.question</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="view_question_search"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Add your first question to the bank
            </p>
        </field>
    </record>

</odoo>
