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

    <!-- Cancellation Request List View -->
    <record id="rental_cancellation_request_view_list" model="ir.ui.view">
        <field name="name">rental.cancellation.request.list</field>
        <field name="model">rental.cancellation.request</field>
        <field name="arch" type="xml">
            <list string="Cancellation Requests">
                <field name="order_id"/>
                <field name="partner_id"/>
                <field name="request_date"/>
                <field name="reason"/>
                <field name="assigned_user_id"/>
                <field name="state"
                       decoration-info="state == 'new'"
                       decoration-success="state in ('confirmed', 'completed')"
                       decoration-warning="state == 'pickup_scheduled'"
                       decoration-danger="state == 'rejected'"
                       widget="badge"/>
            </list>
        </field>
    </record>

    <!-- Cancellation Request Form View -->
    <record id="rental_cancellation_request_view_form" model="ir.ui.view">
        <field name="name">rental.cancellation.request.form</field>
        <field name="model">rental.cancellation.request</field>
        <field name="arch" type="xml">
            <form string="Cancellation Request">
                <header>
                    <button name="action_confirm"
                            type="object"
                            string="Confirm Cancellation"
                            class="btn-primary"
                            invisible="state != 'new'"/>
                    <button name="action_schedule_pickup"
                            type="object"
                            string="Schedule Pickup"
                            class="btn-primary"
                            invisible="state != 'confirmed'"/>
                    <button name="action_complete"
                            type="object"
                            string="Mark Completed"
                            class="btn-success"
                            invisible="state not in ('confirmed', 'pickup_scheduled')"/>
                    <button name="action_reject"
                            type="object"
                            string="Reject"
                            class="btn-danger"
                            invisible="state not in ('new', 'confirmed')"
                            confirm="Are you sure you want to reject this cancellation request?"/>
                    <field name="state" widget="statusbar"
                           statusbar_visible="new,confirmed,pickup_scheduled,completed"/>
                </header>
                <sheet>
                    <div class="oe_title">
                        <h1>
                            <field name="order_id" readonly="1"/>
                        </h1>
                    </div>
                    <group>
                        <group string="Request Details">
                            <field name="partner_id"/>
                            <field name="request_date"/>
                            <field name="requested_pickup_date"/>
                        </group>
                        <group string="Assignment">
                            <field name="assigned_user_id"/>
                            <field name="pickup_activity_id" readonly="1"/>
                        </group>
                    </group>
                    <group string="Reason">
                        <field name="reason" nolabel="1"/>
                    </group>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <!-- Cancellation Request Action -->
    <record id="action_rental_cancellation_request" model="ir.actions.act_window">
        <field name="name">Cancellation Requests</field>
        <field name="res_model">rental.cancellation.request</field>
        <field name="view_mode">list,form</field>
    </record>

</odoo>
