<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <record id="view_res_config_settings_fusion_digitize" model="ir.ui.view">
        <field name="name">res.config.settings.fusion.digitize</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 Digitize" string="Fusion Digitize"
                     name="fusion_digitize"
                     groups="base.group_system">

                    <!-- OPENAI CONFIGURATION -->
                    <block title="OpenAI Configuration" name="fd_ai_config">
                        <setting id="fd_api_key_info" string="API Key Status">
                            <div class="text-muted mt4 mb4">
                                <field name="x_fd_api_key_source" readonly="1" nolabel="1"
                                       class="fw-bold"/>
                            </div>
                            <div invisible="not x_fd_fusion_accounts_installed or x_fd_openai_api_key"
                                 class="alert alert-info mt8 mb8 p-2" role="alert">
                                Fusion Accounts is installed. The shared API key will be used
                                unless you set a dedicated key below.
                            </div>
                            <field name="x_fd_fusion_accounts_installed" invisible="1"/>
                        </setting>
                        <setting id="fd_api_key" string="OpenAI API Key"
                                 help="Set a dedicated key for Fusion Digitize, or leave blank to use the Fusion Accounts key.">
                            <field name="x_fd_openai_api_key" password="True"/>
                        </setting>
                        <setting id="fd_ai_model" string="AI Model"
                                 help="GPT-4o Mini is faster and cheaper (~$0.001/doc). GPT-4o is more accurate for complex or scanned documents.">
                            <field name="x_fd_ai_model"/>
                        </setting>
                    </block>

                    <!-- EXTRACTION SETTINGS -->
                    <block title="Extraction Pipeline" name="fd_extraction_settings">
                        <setting id="fd_tesseract" string="Enable Tesseract OCR"
                                 help="Use free local OCR for scanned PDFs before falling back to AI Vision. Disable if Tesseract results are poor for your documents.">
                            <field name="x_fd_enable_tesseract"/>
                        </setting>
                    </block>

                    <!-- DOCUMENT TYPE TOGGLES -->
                    <block title="Enabled Document Types" name="fd_doc_types">
                        <setting id="fd_vendor_bills" string="Vendor Bills"
                                 help="Digitize incoming vendor bills using Fusion Digitize instead of Odoo IAP.">
                            <field name="x_fd_enable_vendor_bills"/>
                        </setting>
                        <setting id="fd_customer_invoices" string="Customer Invoices"
                                 help="Digitize outgoing customer invoices using Fusion Digitize instead of Odoo IAP.">
                            <field name="x_fd_enable_customer_invoices"/>
                        </setting>
                        <setting id="fd_bank_statements" string="Bank Statements"
                                 help="Digitize bank statements using Fusion Digitize instead of Odoo IAP.">
                            <field name="x_fd_enable_bank_statements"/>
                        </setting>
                    </block>

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