<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <!-- ================================================================= -->
    <!-- SETTINGS PAGE -->
    <!-- ================================================================= -->
    <record id="view_res_config_settings_fusion_accounts" model="ir.ui.view">
        <field name="name">res.config.settings.fusion.accounts</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 Accounts" string="Fusion Accounts"
                     name="fusion_accounts"
                     groups="fusion_accounts.group_fusion_accounts_manager">

                    <!-- AI SETTINGS -->
                    <block title="AI Data Extraction" name="fa_ai_settings">
                        <setting id="fa_ai_enabled" string="Enable AI Extraction"
                                 help="Use OpenAI to automatically extract bill data from emails and PDF attachments.">
                            <field name="x_fa_ai_enabled"/>
                        </setting>
                        <setting id="fa_openai_key" string="OpenAI API Key"
                                 help="Your OpenAI API key for bill data extraction."
                                 invisible="not x_fa_ai_enabled">
                            <field name="x_fa_openai_api_key" password="True"/>
                        </setting>
                        <setting id="fa_ai_model" string="AI Model"
                                 help="Select the OpenAI model. GPT-4o Mini is faster and cheaper, GPT-4o is more accurate."
                                 invisible="not x_fa_ai_enabled">
                            <field name="x_fa_ai_model"/>
                        </setting>
                        <setting id="fa_ai_max_pages" string="Max PDF Pages"
                                 help="Maximum number of PDF pages to send to AI for extraction. More pages = higher cost."
                                 invisible="not x_fa_ai_enabled">
                            <field name="x_fa_ai_max_pages"/>
                        </setting>
                    </block>

                    <!-- VENDOR MATCHING SETTINGS -->
                    <block title="Vendor Matching" name="fa_matching_settings">
                        <setting id="fa_domain_match" string="Domain Matching (Level 2)"
                                 help="Match vendors by email domain when exact email is not found.">
                            <field name="x_fa_enable_domain_match"/>
                        </setting>
                        <setting id="fa_name_match" string="Name Matching (Level 3)"
                                 help="Match vendors by sender display name when email and domain don't match.">
                            <field name="x_fa_enable_name_match"/>
                        </setting>
                        <setting id="fa_auto_block" string="Auto-Block PO Vendors"
                                 help="Automatically block email bill creation for vendors that have active Purchase Orders.">
                            <field name="x_fa_auto_block_po_vendors"/>
                        </setting>
                    </block>

                    <!-- GENERAL SETTINGS -->
                    <block title="General" name="fa_general_settings">
                        <setting id="fa_log_retention" string="Log Retention"
                                 help="Number of days to keep activity logs. Set to 0 to keep forever.">
                            <div class="content-group">
                                <div class="row mt8">
                                    <label for="x_fa_log_retention_days" string="Keep logs for" class="col-3"/>
                                    <field name="x_fa_log_retention_days" class="col-1"/>
                                    <span class="col-2"> days</span>
                                </div>
                            </div>
                        </setting>
                    </block>

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