<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <!-- ================================================================= -->
    <!-- CLIENT CHAT SESSION VIEWS                                         -->
    <!-- ================================================================= -->

    <!-- Chat Session Form View (conversation UI) -->
    <record id="view_fusion_client_chat_session_form" model="ir.ui.view">
        <field name="name">fusion.client.chat.session.form</field>
        <field name="model">fusion.client.chat.session</field>
        <field name="arch" type="xml">
            <form string="Client Intelligence Chat">
                <sheet>
                    <group>
                        <group>
                            <field name="name"/>
                            <field name="profile_id"/>
                        </group>
                        <group>
                            <field name="user_id" readonly="1"/>
                            <field name="state"/>
                        </group>
                    </group>

                    <!-- Conversation History -->
                    <separator string="Conversation"/>
                    <field name="message_ids" nolabel="1" readonly="1">
                        <list decoration-info="role == 'user'" decoration-success="role == 'assistant'"
                              create="0" delete="0" edit="0">
                            <field name="timestamp" width="160px"/>
                            <field name="role" width="80px"/>
                            <field name="content"/>
                        </list>
                    </field>

                    <!-- Input Area -->
                    <separator string="Ask a Question"/>
                    <group>
                        <field name="user_input" nolabel="1" 
                               placeholder="Type your question here... e.g., 'How many clients are from Brampton?' or 'What devices has this client received?'"
                               widget="text"/>
                    </group>
                </sheet>
                <footer>
                    <button name="action_send_message" type="object" 
                            string="Send" class="btn-primary" icon="fa-paper-plane"/>
                    <button string="Close" class="btn-secondary" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <!-- Chat Session List View -->
    <record id="view_fusion_client_chat_session_list" model="ir.ui.view">
        <field name="name">fusion.client.chat.session.list</field>
        <field name="model">fusion.client.chat.session</field>
        <field name="arch" type="xml">
            <list string="Chat Sessions">
                <field name="name"/>
                <field name="profile_id"/>
                <field name="user_id"/>
                <field name="create_date"/>
                <field name="state"/>
            </list>
        </field>
    </record>

    <!-- ================================================================= -->
    <!-- ACTIONS                                                           -->
    <!-- ================================================================= -->

    <!-- Global Chat Action (create new session) -->
    <record id="action_fc_client_chat_new" model="ir.actions.act_window">
        <field name="name">Client Intelligence</field>
        <field name="res_model">fusion.client.chat.session</field>
        <field name="view_mode">form</field>
        <field name="target">current</field>
        <field name="context">{'default_name': 'New Chat'}</field>
    </record>

    <!-- Chat History Action -->
    <record id="action_fc_client_chat_history" model="ir.actions.act_window">
        <field name="name">Chat History</field>
        <field name="res_model">fusion.client.chat.session</field>
        <field name="view_mode">list,form</field>
    </record>
</odoo>
