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

    <!-- ================================================================== -->
    <!-- SYNC CONFIG - FORM VIEW                                            -->
    <!-- ================================================================== -->
    <record id="view_task_sync_config_form" model="ir.ui.view">
        <field name="name">fusion.task.sync.config.form</field>
        <field name="model">fusion.task.sync.config</field>
        <field name="arch" type="xml">
            <form string="Task Sync Configuration">
                <header>
                    <button name="action_test_connection" type="object"
                            string="Test Connection" class="btn-secondary" icon="fa-plug"/>
                    <button name="action_sync_now" type="object"
                            string="Sync Now" class="btn-success" icon="fa-sync"/>
                </header>
                <sheet>
                    <div class="oe_title">
                        <h1><field name="name" placeholder="e.g. Westin Healthcare"/></h1>
                    </div>
                    <group>
                        <group string="Connection">
                            <field name="instance_id" placeholder="e.g. westin"/>
                            <field name="url" placeholder="http://192.168.1.40:8069"/>
                            <field name="database" placeholder="e.g. westin-v19"/>
                            <field name="username" placeholder="e.g. admin"/>
                            <field name="api_key" password="True"/>
                            <field name="active"/>
                        </group>
                        <group string="Status">
                            <field name="last_sync"/>
                            <field name="last_sync_error" readonly="1"/>
                        </group>
                    </group>
                    <div class="alert alert-info mt-3">
                        <i class="fa fa-info-circle"/>
                        Technicians are matched across instances by their
                        <strong>Tech Sync ID</strong> field (Settings &gt; Users).
                        Set the same ID (e.g. "gordy") on both instances for each shared technician.
                    </div>
                </sheet>
            </form>
        </field>
    </record>

    <!-- ================================================================== -->
    <!-- SYNC CONFIG - LIST VIEW                                            -->
    <!-- ================================================================== -->
    <record id="view_task_sync_config_list" model="ir.ui.view">
        <field name="name">fusion.task.sync.config.list</field>
        <field name="model">fusion.task.sync.config</field>
        <field name="arch" type="xml">
            <list>
                <field name="name"/>
                <field name="instance_id"/>
                <field name="url"/>
                <field name="database"/>
                <field name="active"/>
                <field name="last_sync"/>
            </list>
        </field>
    </record>

    <!-- ================================================================== -->
    <!-- SYNC CONFIG - ACTION + MENU                                        -->
    <!-- ================================================================== -->
    <record id="action_task_sync_config" model="ir.actions.act_window">
        <field name="name">Task Sync Instances</field>
        <field name="res_model">fusion.task.sync.config</field>
        <field name="view_mode">list,form</field>
    </record>

    <menuitem id="menu_task_sync_config"
              name="Task Sync"
              parent="menu_technician_config"
              action="action_task_sync_config"
              sequence="10"/>

</odoo>
