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

    <record id="view_backup_conf_form" model="ir.ui.view">
        <field name="model">db.backup</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button name="action_backup" type="object" string="Execute backup" class="oe_highlight"/>
                </header>
                <div class="oe_title">
                   <h1><field name="name"/></h1>
                </div>
                <group string="Basic backup configuration">
                    <field name="folder"/>
                    <field name="days_to_keep"/>
                    <field name="method"/>
                    <field name="backup_format"/>
                </group>
                <div attrs="{'invisible': [('method', '!=', 'sftp')]}">
                    <div class="bg-warning">
                        <h3>Warning:</h3>
                        Use SFTP with caution! This writes files to external servers under the path you specify.
                    </div>
                    <group string="SFTP Settings">
                        <field name="sftp_host" placeholder="sftp.example.com"/>
                        <field name="sftp_port"/>
                        <field name="sftp_user" placeholder="john"/>
                        <field name="sftp_password"/>
                        <field
                            name="sftp_private_key"
                            placeholder="/home/odoo/.ssh/id_rsa"/>
                        <button
                            name="action_sftp_test_connection"
                            type="object"
                            string="Test SFTP Connection"
                            icon="fa-television"/>
                    </group>
                </div>
                <separator string="Help" colspan="2"/>
                <div>
                    Automatic backups of the database can be scheduled as follows:
                    <ol>
                        <li>Go to Settings / Technical / Automation / Scheduled Actions.</li>
                        <li>Search the action named 'Backup scheduler'.</li>
                        <li>Set the scheduler to active and fill in how often you want backups generated.</li>
                    </ol>
                </div>
            </form>
        </field>
    </record>

    <record id="view_backup_conf_tree" model="ir.ui.view">
        <field name="model">db.backup</field>
        <field name="arch" type="xml">
            <tree>
                <field name="name"/>
                <field name="folder"/>
                <field name="days_to_keep"/>
            </tree>
        </field>
    </record>

    <record id="view_backup_conf_search" model="ir.ui.view">
        <field name="model">db.backup</field>
        <field name="arch" type="xml">
            <search>
                <field name="name"/>
                <field name="folder"/>
                <field name="sftp_host"/>
            </search>
        </field>
    </record>

    <act_window
        name="Automated Backups"
        id="action_backup_conf_form"
        res_model="db.backup"/>

    <menuitem
        parent="base.next_id_9"
        action="action_backup_conf_form"
        id="backup_conf_menu"/>

    <!-- Execute backup from "More" menu -->
    <record id="action_server_backup" model="ir.actions.server">
        <field name="name">Execute backup(s)</field>
        <field name="type">ir.actions.server</field>
        <field name="model_id" ref="model_db_backup" />
        <field name="binding_model_id" ref="model_db_backup" />
        <field name="state">code</field>
        <field name="code">records.action_backup()</field>
    </record>

</odoo>