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

    <!-- Poynt Terminal Tree View -->
    <record id="poynt_terminal_view_list" model="ir.ui.view">
        <field name="name">poynt.terminal.list</field>
        <field name="model">poynt.terminal</field>
        <field name="arch" type="xml">
            <list string="Poynt Terminals">
                <field name="name"/>
                <field name="device_id"/>
                <field name="serial_number"/>
                <field name="provider_id"/>
                <field name="store_id_poynt"/>
                <field name="status" widget="badge"
                       decoration-success="status == 'online'"
                       decoration-danger="status == 'offline'"
                       decoration-warning="status == 'unknown'"/>
                <field name="last_seen"/>
            </list>
        </field>
    </record>

    <!-- Poynt Terminal Form View -->
    <record id="poynt_terminal_view_form" model="ir.ui.view">
        <field name="name">poynt.terminal.form</field>
        <field name="model">poynt.terminal</field>
        <field name="arch" type="xml">
            <form string="Poynt Terminal">
                <header>
                    <button string="Refresh Status"
                            type="object"
                            name="action_refresh_status"
                            class="btn-primary"/>
                </header>
                <sheet>
                    <div class="oe_title">
                        <h1>
                            <field name="name" placeholder="Terminal Name"/>
                        </h1>
                    </div>
                    <group>
                        <group string="Device Information">
                            <field name="device_id"/>
                            <field name="serial_number"/>
                            <field name="status" widget="badge"
                                   decoration-success="status == 'online'"
                                   decoration-danger="status == 'offline'"
                                   decoration-warning="status == 'unknown'"/>
                            <field name="last_seen"/>
                        </group>
                        <group string="Configuration">
                            <field name="provider_id"/>
                            <field name="store_id_poynt"/>
                            <field name="active"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Poynt Terminal Search View -->
    <record id="poynt_terminal_view_search" model="ir.ui.view">
        <field name="name">poynt.terminal.search</field>
        <field name="model">poynt.terminal</field>
        <field name="arch" type="xml">
            <search string="Poynt Terminals">
                <field name="name"/>
                <field name="device_id"/>
                <field name="serial_number"/>
                <field name="provider_id"/>
                <filter string="Online" name="online"
                        domain="[('status', '=', 'online')]"/>
                <filter string="Offline" name="offline"
                        domain="[('status', '=', 'offline')]"/>
                <separator/>
                <filter string="Status" name="group_status"
                        context="{'group_by': 'status'}"/>
                <filter string="Provider" name="group_provider"
                        context="{'group_by': 'provider_id'}"/>
            </search>
        </field>
    </record>

    <!-- Poynt Terminal Action -->
    <record id="action_poynt_terminal" model="ir.actions.act_window">
        <field name="name">Poynt Terminals</field>
        <field name="res_model">poynt.terminal</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="poynt_terminal_view_search"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No Poynt terminals configured yet.
            </p>
            <p>
                Click "Fetch Terminals" on your Poynt payment provider to sync
                terminal devices from the Poynt Cloud, or add one manually.
            </p>
        </field>
    </record>

    <!-- Menu entry as sibling of Payment Providers under Online Payments -->
    <menuitem id="menu_poynt_terminal"
              name="Poynt Terminals"
              parent="account.root_payment_menu"
              action="action_poynt_terminal"
              sequence="15"
              groups="fusion_poynt.group_fusion_poynt_user"/>

</odoo>
