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

    <!-- Terminal form view -->
    <record id="clover_terminal_form" model="ir.ui.view">
        <field name="name">clover.terminal.form</field>
        <field name="model">clover.terminal</field>
        <field name="arch" type="xml">
            <form string="Clover Terminal">
                <header>
                    <button name="action_refresh_status"
                            string="Ping Device"
                            type="object"
                            class="btn-primary"
                            icon="fa-wifi"/>
                    <button name="action_display_welcome"
                            string="Display Welcome"
                            type="object"
                            class="btn-secondary"
                            icon="fa-tv"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box"/>
                    <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger"
                            invisible="active"/>
                    <group>
                        <group string="Device Information">
                            <field name="name" placeholder="e.g. Front Desk, Back Office"/>
                            <field name="clover_device_name" readonly="1"
                                   invisible="not clover_device_name"/>
                            <field name="serial_number"/>
                            <field name="device_id" readonly="1"/>
                            <field name="model_name" readonly="1"/>
                        </group>
                        <group string="Status">
                            <field name="provider_id"/>
                            <field name="status"/>
                            <field name="last_seen"/>
                            <field name="active" invisible="1"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Terminal list view -->
    <record id="clover_terminal_list" model="ir.ui.view">
        <field name="name">clover.terminal.list</field>
        <field name="model">clover.terminal</field>
        <field name="arch" type="xml">
            <list string="Clover Terminals">
                <field name="name"/>
                <field name="serial_number"/>
                <field name="model_name"/>
                <field name="provider_id"/>
                <field name="status" decoration-success="status == 'online'"
                       decoration-danger="status == 'offline'"
                       decoration-warning="status == 'unknown'"
                       widget="badge"/>
                <field name="last_seen"/>
            </list>
        </field>
    </record>

    <!-- Terminal action -->
    <record id="action_clover_terminals" model="ir.actions.act_window">
        <field name="name">Clover Terminals</field>
        <field name="res_model">clover.terminal</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No Clover terminals configured yet.
            </p>
            <p>
                Use the "Sync Terminals" button on the Clover payment provider
                to automatically fetch devices from your merchant account,
                or add them manually.
            </p>
        </field>
    </record>

    <!-- Menu item under Accounting > Configuration -->
    <menuitem id="menu_clover_terminals"
              name="Clover Terminals"
              parent="account.menu_finance_configuration"
              action="action_clover_terminals"
              sequence="40"
              groups="fusion_clover.group_fusion_clover_admin"/>

    <!-- Add Sync Terminals button to payment provider form -->
    <record id="payment_provider_form_terminal_button" model="ir.ui.view">
        <field name="name">payment.provider.form.clover.terminal</field>
        <field name="model">payment.provider</field>
        <field name="inherit_id" ref="fusion_clover.payment_provider_form"/>
        <field name="arch" type="xml">
            <xpath expr="//button[@name='action_clover_test_connection']" position="after">
                <button string="Sync Terminals"
                        type="object"
                        name="action_sync_terminals"
                        class="btn-secondary"
                        icon="fa-refresh"
                        invisible="not clover_merchant_id or (not clover_rest_api_token and not clover_api_key)"
                        colspan="2"/>
            </xpath>
        </field>
    </record>

</odoo>
