from django.db import models
from django.utils.translation import gettext_lazy as _

from oscar.core.loading import get_classes

from ocyan.main.loading import get_baseclass

BaseAbstractLineAttribute = get_baseclass(
    "order.abstract_models",
    "AbstractLineAttribute",
    "ocyan.plugin.oscar_order.oxyan_order_extension",
)
JSONDecoder, JSONEncoder = get_classes(
    "catalogue.decoder", ["JSONDecoder", "JSONEncoder"]
)


class AbstractLineAttribute(BaseAbstractLineAttribute):
    value = models.JSONField(_("Value"), encoder=JSONEncoder, decoder=JSONDecoder)

    class Meta(BaseAbstractLineAttribute.Meta):
        abstract = True
