# -*- coding: utf-8 -*-
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from ocyan.core.fender import config

from ocyan.plugin.oscar_checkout.checkout.models import (
    FixedSurcharge,
    PaymentMethod,
    PercentageSurcharge,
)

INVOICE_ACTIVE = config.get("oscar_communications", "invoice", False)


# Register your models here.
class PaymentMethodAdmin(admin.ModelAdmin):
    fieldsets = (
        (
            None,
            {
                "fields": (
                    ("label", "key", "send_invoice")
                    if INVOICE_ACTIVE
                    else ("label", "key")
                )
            },
        ),
        (_("Availability"), {"fields": ("country",)}),
        (_("Limits"), {"fields": ("min_amount", "max_amount")}),
        (
            _("Permissions"),
            {"classes": ("collapse",), "fields": ("requires_permission",)},
        ),
        (_("Ordering"), {"fields": ("ordering",)}),
    )

    filter_horizontal = ["country"]


class SurchargeAdmin(admin.ModelAdmin):
    filter_horizontal = ["country", "payment_method"]


admin.site.register(PaymentMethod, PaymentMethodAdmin)
admin.site.register(FixedSurcharge, SurchargeAdmin)
admin.site.register(PercentageSurcharge, SurchargeAdmin)
