<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Tree View -->
    <record id="view_saas_restaurant_tree" model="ir.ui.view">
        <field name="name">saas.restaurant.tree</field>
        <field name="model">saas.restaurant</field>
        <field name="arch" type="xml">
            <tree string="Restaurants">
                <field name="name"/>
                <field name="owner_name"/>
                <field name="email"/>
                <field name="subdomain"/>
                <field name="plan_id"/>
                <field name="status" widget="badge" decoration-success="status == 'active'" decoration-info="status == 'draft'" decoration-danger="status == 'suspended' or status == 'expired'"/>
                <field name="expiry_date"/>
            </tree>
        </field>
    </record>

    <!-- Form View -->
    <record id="view_saas_restaurant_form" model="ir.ui.view">
        <field name="name">saas.restaurant.form</field>
        <field name="model">saas.restaurant</field>
        <field name="arch" type="xml">
            <form string="Restaurant Tenant">
                <header>
                    <button name="action_create_database" string="Provision Database" type="object" class="oe_highlight" invisible="status != 'draft'"/>
                    <button name="action_suspend" string="Suspend Subscription" type="object" class="btn-danger" invisible="status != 'active'"/>
                    <button name="action_activate" string="Activate Subscription" type="object" class="oe_highlight" invisible="status not in ['suspended', 'expired']"/>
                    <field name="status" widget="statusbar" statusbar_visible="draft,active,suspended,expired"/>
                </header>
                <sheet>
                    <field name="logo" widget="image" class="oe_avatar" options="{'preview_image': 'logo'}"/>
                    <div class="oe_title">
                        <label for="name" class="oe_edit_only"/>
                        <h1>
                            <field name="name" placeholder="Restaurant Name"/>
                        </h1>
                    </div>
                    <group>
                        <group string="Owner Information">
                            <field name="owner_name"/>
                            <field name="email"/>
                            <field name="phone"/>
                        </group>
                        <group string="Address">
                            <field name="street"/>
                            <field name="city"/>
                            <field name="country_id"/>
                        </group>
                    </group>
                    <group>
                        <group string="Tenant Deployment">
                            <field name="database_name"/>
                            <field name="subdomain"/>
                        </group>
                        <group string="Subscription Details">
                            <field name="plan_id"/>
                            <field name="billing_cycle"/>
                            <field name="start_date"/>
                            <field name="expiry_date"/>
                        </group>
                    </group>
                    <group>
                        <group string="Localizations">
                            <field name="currency_id"/>
                            <field name="timezone"/>
                        </group>
                    </group>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids"/>
                    <field name="activity_ids"/>
                    <field name="message_ids"/>
                </div>
            </form>
        </field>
    </record>

    <!-- Search View -->
    <record id="view_saas_restaurant_search" model="ir.ui.view">
        <field name="name">saas.restaurant.search</field>
        <field name="model">saas.restaurant</field>
        <field name="arch" type="xml">
            <search string="Search Restaurants">
                <field name="name"/>
                <field name="owner_name"/>
                <field name="email"/>
                <field name="subdomain"/>
                <filter string="Draft" name="status_draft" domain="[('status', '=', 'draft')]"/>
                <filter string="Active" name="status_active" domain="[('status', '=', 'active')]"/>
                <filter string="Suspended" name="status_suspended" domain="[('status', '=', 'suspended')]"/>
                <filter string="Expired" name="status_expired" domain="[('status', '=', 'expired')]"/>
                <group expand="0" string="Group By">
                    <filter string="Plan" name="group_by_plan" context="{'group_by': 'plan_id'}"/>
                    <filter string="Status" name="group_by_status" context="{'group_by': 'status'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Action -->
    <record id="action_saas_restaurant" model="ir.actions.act_window">
        <field name="name">Restaurants</field>
        <field name="res_model">saas.restaurant</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="view_saas_restaurant_search"/>
    </record>

    <!-- Menuitem -->
    <menuitem id="menu_saas_restaurant"
              name="Restaurants List"
              parent="menu_saas_tenants"
              action="action_saas_restaurant"
              sequence="10"/>
</odoo>
