<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- KYC Form View -->
    <record id="view_marketplace_kyc_form" model="ir.ui.view">
        <field name="name">kyc.request.form</field>
        <field name="model">kyc.request</field>
        <field name="arch" type="xml">
            <form string="KYC Request">
                <header>
                    <button name="action_start_review" type="object" 
                           string="Start Review" class="oe_highlight"/>
                    <button name="action_approve" type="object" 
                           string="Approve" class="btn-success"/>
                    <button name="action_reject" type="object" 
                           string="Reject" class="btn-danger"/>
                    <field name="status" widget="statusbar" 
                           statusbar_visible="pending,in_review,approved,rejected"/>
                </header>
                <sheet>
                    <div class="oe_title">
                        <label for="name"/>
                        <h1><field name="name"/></h1>
                    </div>
                    <group>
                        <group name="team_info" string="Team Information">
                            <field name="team_name"/>
                            <field name="team_uuid"/>
                            <field name="owner_id"/>
                            <field name="logto_org_id"/>
                            <field name="submitted_date"/>
                        </group>
                        <group name="review_info" string="Review Information">
                            <field name="score" widget="progressbar"/>
                            <field name="can_create_orders"/>
                            <field name="reviewer_id"/>
                            <field name="reviewed_date"/>
                            <field name="approved_date" attrs="{'invisible': [('status', '!=', 'approved')]}"/>
                            <field name="days_pending"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Company Information">
                            <group>
                                <field name="company_name"/>
                                <field name="company_tax_number"/>
                                <field name="company_registration"/>
                                <field name="company_address"/>
                            </group>
                        </page>
                        <page string="Documents">
                            <field name="documents"/>
                        </page>
                        <page string="Review Notes">
                            <field name="review_notes" widget="html"/>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids"/>
                    <field name="activity_ids"/>
                    <field name="message_ids"/>
                </div>
            </form>
        </field>
    </record>

    <!-- KYC Tree View -->
    <record id="view_marketplace_kyc_tree" model="ir.ui.view">
        <field name="name">kyc.request.tree</field>
        <field name="model">kyc.request</field>
        <field name="arch" type="xml">
            <tree string="KYC Requests" decoration-success="status=='approved'" 
                  decoration-danger="status=='rejected'" decoration-warning="status=='pending'">
                <field name="name"/>
                <field name="team_name"/>
                <field name="status" widget="badge" 
                       decoration-success="status=='approved'"
                       decoration-danger="status=='rejected'"
                       decoration-warning="status=='pending'"
                       decoration-info="status=='in_review'"/>
                <field name="score" widget="progressbar"/>
                <field name="can_create_orders"/>
                <field name="submitted_date"/>
                <field name="reviewer_id"/>
                <field name="days_pending"/>
            </tree>
        </field>
    </record>

    <!-- KYC Search View -->
    <record id="view_marketplace_kyc_search" model="ir.ui.view">
        <field name="name">kyc.request.search</field>
        <field name="model">kyc.request</field>
        <field name="arch" type="xml">
            <search string="KYC Requests">
                <field name="name"/>
                <field name="team_name"/>
                <field name="team_uuid"/>
                <field name="reviewer_id"/>
                <filter string="Pending" name="pending" domain="[('status','=','pending')]"/>
                <filter string="In Review" name="in_review" domain="[('status','=','in_review')]"/>
                <filter string="Approved" name="approved" domain="[('status','=','approved')]"/>
                <filter string="Rejected" name="rejected" domain="[('status','=','rejected')]"/>
                <separator/>
                <filter string="My Reviews" name="my_reviews" domain="[('reviewer_id','=',uid)]"/>
                <group expand="0" string="Group By">
                    <filter string="Status" name="group_status" context="{'group_by':'status'}"/>
                    <filter string="Reviewer" name="group_reviewer" context="{'group_by':'reviewer_id'}"/>
                    <filter string="Submission Date" name="group_date" context="{'group_by':'submitted_date'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Action -->
    <record id="action_marketplace_kyc" model="ir.actions.act_window">
        <field name="name">KYC Requests</field>
        <field name="res_model">kyc.request</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{'search_default_pending': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create your first KYC request
            </p>
            <p>
                KYC requests are created automatically when teams are formed
                and need verification before they can create orders.
            </p>
        </field>
    </record>

    <!-- Menu -->
    <menuitem id="menu_marketplace_main" name="Marketplace" sequence="10"/>
    <menuitem id="menu_marketplace_kyc" name="KYC Management" parent="menu_marketplace_main" sequence="10"/>
    <menuitem id="menu_marketplace_kyc_requests" name="KYC Requests" parent="menu_marketplace_kyc" 
              action="action_marketplace_kyc" sequence="10"/>

</odoo>