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

    <record id="view_helpdesk_mail_server_tree" model="ir.ui.view">
        <field name="name">so.helpdesk.mail.server.tree</field>
        <field name="model">so.helpdesk.mail.server</field>
        <field name="arch" type="xml">
            <tree>
                <field name="name"/>
                <field name="user"/>
                <field name="folder"/>
                <field name="default_team_id"/>
                <field name="state"/>
                <field name="last_fetch_date"/>
                <field name="ticket_count"/>
                <field name="active"/>
            </tree>
        </field>
    </record>

    <record id="view_helpdesk_mail_server_form" model="ir.ui.view">
        <field name="name">so.helpdesk.mail.server.form</field>
        <field name="model">so.helpdesk.mail.server</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button name="action_test_connection" type="object"
                            string="Test Connection" class="btn-primary"/>
                    <button name="action_fetch_now" type="object"
                            string="Fetch Now" class="btn-secondary"/>
                    <field name="state" widget="statusbar"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button class="oe_stat_button" icon="fa-life-ring" type="action"
                                name="%(so_helpdesk.action_helpdesk_ticket)d"
                                context="{'search_default_mail_server_id': active_id}">
                            <field name="ticket_count" widget="statinfo" string="Tickets"/>
                        </button>
                    </div>
                    <group>
                        <group string="Mailbox">
                            <field name="name"/>
                            <field name="active"/>
                            <field name="server"/>
                            <field name="port"/>
                            <field name="is_ssl"/>
                            <field name="user"/>
                            <field name="password" password="True"/>
                            <field name="folder"/>
                        </group>
                        <group string="Routing">
                            <field name="default_team_id"/>
                            <field name="from_name"/>
                            <field name="from_email"/>
                            <field name="company_id" groups="base.group_multi_company"/>
                            <field name="last_fetch_date" readonly="1"/>
                            <field name="last_uid" readonly="1"/>
                            <field name="last_error" readonly="1"/>
                        </group>
                    </group>
                    <div class="alert alert-info" role="alert">
                        Incoming emails create tickets automatically. Replies containing the
                        ticket reference (e.g. SO-HD/2026/00001) are appended to the existing thread.
                        Agent comments on the ticket board email the customer until the ticket is closed.
                    </div>
                </sheet>
            </form>
        </field>
    </record>

    <record id="action_helpdesk_mail_server" model="ir.actions.act_window">
        <field name="name">Support Mailboxes</field>
        <field name="res_model">so.helpdesk.mail.server</field>
        <field name="view_mode">tree,form</field>
    </record>

</odoo>
