<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Tree View -->
    <record id="view_saas_backup_tree" model="ir.ui.view">
        <field name="name">saas.backup.tree</field>
        <field name="model">saas.backup</field>
        <field name="arch" type="xml">
            <tree string="SaaS Backups" create="false">
                <field name="restaurant_id"/>
                <field name="database_name"/>
                <field name="backup_file"/>
                <field name="timestamp"/>
                <field name="storage_type"/>
                <field name="status" widget="badge" decoration-success="status == 'success'" decoration-danger="status == 'failed'"/>
            </tree>
        </field>
    </record>

    <!-- Form View -->
    <record id="view_saas_backup_form" model="ir.ui.view">
        <field name="name">saas.backup.form</field>
        <field name="model">saas.backup</field>
        <field name="arch" type="xml">
            <form string="Backup Record" edit="false" create="false">
                <header>
                    <button name="action_backup_database" string="Run Backup Now" type="object" class="oe_highlight" invisible="status == 'success'"/>
                    <field name="status" widget="statusbar" statusbar_visible="failed,success"/>
                </header>
                <sheet>
                    <group>
                        <group string="Target Database">
                            <field name="restaurant_id"/>
                            <field name="database_name"/>
                        </group>
                        <group string="Execution Metadata">
                            <field name="timestamp"/>
                            <field name="storage_type"/>
                            <field name="backup_file"/>
                            <field name="s3_url" widget="url" invisible="not s3_url"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Action -->
    <record id="action_saas_backup" model="ir.actions.act_window">
        <field name="name">Database Backups</field>
        <field name="res_model">saas.backup</field>
        <field name="view_mode">tree,form</field>
    </record>

    <!-- Menuitem -->
    <menuitem id="menu_saas_backup"
              name="Database Backups"
              parent="menu_saas_tenants"
              action="action_saas_backup"
              sequence="20"/>
</odoo>
