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

    <record id="res_config_settings_view_form_fusion_inventory" model="ir.ui.view">
        <field name="name">res.config.settings.view.form.fusion.inventory</field>
        <field name="model">res.config.settings</field>
        <field name="inherit_id" ref="base.res_config_settings_view_form"/>
        <field name="arch" type="xml">
            <xpath expr="//form" position="inside">
                <app data-string="Fusion Inventory" string="Fusion Inventory"
                     name="fusion_inventory"
                     groups="stock.group_stock_manager">

                    <!-- GENERAL SETTINGS -->
                    <h2>General</h2>
                    <div class="row mt-4 o_settings_container">

                        <div class="col-12 col-lg-6 o_setting_box">
                            <div class="o_setting_left_pane">
                                <field name="fi_auto_update_cost"/>
                            </div>
                            <div class="o_setting_right_pane">
                                <label for="fi_auto_update_cost"/>
                                <div class="text-muted">
                                    Automatically update product cost when a vendor bill is confirmed.
                                    Uses the latest bill line price (zero-price lines are skipped).
                                </div>
                                <div class="mt-3">
                                    <button name="action_sync_all_costs_from_bills"
                                            type="object"
                                            string="Sync All Product Costs Now"
                                            class="btn-secondary"
                                            icon="fa-refresh"
                                            confirm="This will update every product's cost to its latest vendor bill price. Continue?"/>
                                </div>
                            </div>
                        </div>

                        <div class="col-12 col-lg-6 o_setting_box">
                            <div class="o_setting_right_pane">
                                <span class="o_form_label">Default Margin (%)</span>
                                <div class="text-muted">
                                    Default margin percentage applied to newly created products.
                                </div>
                                <div class="mt-2">
                                    <field name="fi_default_margin" style="max-width: 100px;"/> %
                                </div>
                            </div>
                        </div>

                        <div class="col-12 col-lg-6 o_setting_box">
                            <div class="o_setting_right_pane">
                                <span class="o_form_label">Booking Hold Duration</span>
                                <div class="text-muted">
                                    How many hours a product booking holds in the inventory sheet
                                    before automatically expiring.
                                </div>
                                <div class="mt-2">
                                    <field name="fi_booking_hold_hours" style="max-width: 80px;"/> hours
                                </div>
                            </div>
                        </div>

                    </div>

                    <!-- CASE CONVERSION -->
                    <h2>Product Name Case Conversion</h2>
                    <div class="row mt-4 o_settings_container">

                        <div class="col-12 col-lg-6 o_setting_box">
                            <div class="o_setting_right_pane">
                                <span class="o_form_label">Global Case Conversion</span>
                                <div class="text-muted">
                                    Automatically convert ALL product names to the selected case.
                                    This overrides individual product settings and applies to new products.
                                    Set to "No Conversion" to let individual products control their own case.
                                </div>
                                <div class="mt-3">
                                    <field name="fi_case_conversion" widget="radio"/>
                                </div>
                                <div class="mt-3">
                                    <button name="action_apply_case_conversion_all"
                                            type="object" string="Apply to All Existing Products"
                                            class="btn-secondary"
                                            confirm="This will convert all existing product names. Continue?"/>
                                </div>
                            </div>
                        </div>

                    </div>

                    <!-- OPENAI / AI -->
                    <h2>AI Configuration</h2>
                    <div class="row mt-4 o_settings_container">

                        <div class="col-12 col-lg-6 o_setting_box">
                            <div class="o_setting_right_pane">
                                <span class="o_form_label">OpenAI API Key</span>
                                <div class="text-muted">
                                    Used for discrepancy analysis and notes parsing.
                                    If empty, falls back to the Fusion Digitize API key.
                                </div>
                                <div class="mt-2">
                                    <field name="fi_openai_api_key" password="True"
                                           placeholder="Leave empty to use Fusion Digitize key"/>
                                </div>
                            </div>
                        </div>

                    </div>

                </app>
            </xpath>
        </field>
    </record>

</odoo>
