# Copyright 2026 - Today Kidekoop
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields  # type: ignore
from odoo import models  # type: ignore


class ResConfigSettings(models.TransientModel):
    _inherit = "res.config.settings"

    total_margin_min_percent = fields.Float(
        string="Minimum Total Margin (%)",
        default=0.0,
        help="Minimum total margin percentage allowed for pricelist items using "
        "Total Margin Mode. If the calculated margin is below this value, "
        "the price will be adjusted to meet the minimum.\n\n"
        "Example: If set to 10%, a product with base price 100€ will have "
        "a minimum final price of 110€ (markup) or 111.11€ (commercial margin).\n\n"
        "Set to 0 to disable minimum margin control.",
        config_parameter="product_pricelist_total_margin.min_percent",
    )

    total_margin_max_percent = fields.Float(
        string="Maximum Total Margin (%)",
        default=0.0,
        help="Maximum total margin percentage allowed for pricelist items using "
        "Total Margin Mode. If the calculated margin exceeds this value, "
        "the price will be adjusted to meet the maximum.\n\n"
        "Example: If set to 50%, a product with base price 100€ will have "
        "a maximum final price of 150€ (markup) or 200€ (commercial margin).\n\n"
        "Set to 0 to disable maximum margin control.",
        config_parameter="product_pricelist_total_margin.max_percent",
    )

    global_margin_type = fields.Selection(
        selection=[
            ("markup", "Markup (on cost)"),
            ("margin", "Commercial Margin (on list price)"),
        ],
        string="Global Limits Calculation",
        default="markup",
        help="Calculation method for global minimum and maximum margin limits:\n"
        "- Markup: Price = Cost × (1 + margin%). Applied limits are calculated as markup.\n"
        "  Example: Min 10% → Price >= Cost × 1.10\n\n"
        "- Commercial Margin: Price = Cost / (1 - margin%). Applied limits are commercial margin.\n"
        "  Example: Min 10% → Price >= Cost / 0.90\n\n"
        "This affects how the minimum and maximum percentages above are interpreted.",
        config_parameter="product_pricelist_total_margin.global_margin_type",
    )
