from django.db import models
import ulid
from XCMS_PIM.models import WorkspaceUser
from django.db.models.constraints import UniqueConstraint
from django.forms.models import model_to_dict
from app.models.product_classification_model import ProductClassificationModel
from app.models.attributes_model import AttributesModel
from app.models.channel_model import ChannelModel
from XCMS_PIM.pim_cnsts import *


class ULIDField(models.CharField):
    def __init__(self, *args, **kwargs):
        kwargs["max_length"] = 26
        super(ULIDField, self).__init__(*args, **kwargs)

    def db_type(self, connection):
        return "char(26)"


class ChannelOutputModel(models.Model):
    channel = models.ForeignKey(
        ChannelModel,
        related_name="channel_outputs",
        null=False,
        blank=False,
        on_delete=models.DO_NOTHING,
        db_column="channel_cd",
    )
    product_classification = models.ForeignKey(
        ProductClassificationModel,
        related_name="channel_outputs",
        null=False,
        blank=False,
        on_delete=models.DO_NOTHING,
        db_column="product_classification_cd",
    )
    attribute = models.ForeignKey(
        AttributesModel,
        related_name="channel_outputs",
        null=False,
        blank=False,
        on_delete=models.DO_NOTHING,
        db_column="attribute_cd",
    )
    output_idx = models.SmallIntegerField()
    name = models.CharField(max_length=256)
    atr_merge_item_nos = models.CharField(max_length=512)
    merge_sep_text = models.CharField(max_length=20)
    output_formula = models.CharField(max_length=256)
    hidden = models.CharField(max_length=1)

    class Meta:
        managed = False
        db_table = "output_channels_data_t"
