<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Submission History Tree View -->
    <record id="view_fusion_submission_history_tree" model="ir.ui.view">
        <field name="name">fusion.submission.history.tree</field>
        <field name="model">fusion.submission.history</field>
        <field name="arch" type="xml">
            <list string="Submission History" create="0">
                <field name="submission_number"/>
                <field name="submission_type"/>
                <field name="submission_date"/>
                <field name="submitted_by_id"/>
                <field name="result" widget="badge" 
                       decoration-success="result == 'accepted' or result == 'approved'"
                       decoration-danger="result == 'rejected' or result == 'denied'"
                       decoration-info="result == 'pending'"/>
                <field name="result_date"/>
                <field name="rejection_reason" optional="hide"/>
                <field name="correction_notes" optional="hide"/>
            </list>
        </field>
    </record>

    <!-- Submission History Form View -->
    <record id="view_fusion_submission_history_form" model="ir.ui.view">
        <field name="name">fusion.submission.history.form</field>
        <field name="model">fusion.submission.history</field>
        <field name="arch" type="xml">
            <form string="Submission History">
                <sheet>
                    <div class="oe_title">
                        <h1>
                            <field name="display_name" readonly="1"/>
                        </h1>
                    </div>
                    
                    <group>
                        <group string="Submission Details">
                            <field name="sale_order_id" readonly="1"/>
                            <field name="submission_number" readonly="1"/>
                            <field name="submission_type" readonly="1"/>
                            <field name="submission_date" readonly="1"/>
                            <field name="submitted_by_id" readonly="1"/>
                        </group>
                        <group string="Result">
                            <field name="result"/>
                            <field name="result_date"/>
                            <field name="rejection_reason" invisible="result != 'rejected'"/>
                            <field name="rejection_details" invisible="result != 'rejected'"/>
                        </group>
                    </group>
                    
                    <group string="Documents Submitted" invisible="not final_application and not xml_file">
                        <group>
                            <field name="final_application" filename="final_application_filename"/>
                            <field name="final_application_filename" invisible="1"/>
                        </group>
                        <group>
                            <field name="xml_file" filename="xml_filename"/>
                            <field name="xml_filename" invisible="1"/>
                        </group>
                    </group>
                    
                    <group string="Correction Notes" invisible="not correction_notes">
                        <field name="correction_notes" nolabel="1" colspan="2"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Action to view submission history -->
    <record id="action_fusion_submission_history" model="ir.actions.act_window">
        <field name="name">Submission History</field>
        <field name="res_model">fusion.submission.history</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[]</field>
        <field name="context">{}</field>
    </record>
</odoo>
