from django.db import models
from django.db.models.constraints import UniqueConstraint
import ulid
from XCMS_PIM.models import WorkspaceUser


class ChannelModel(models.Model):
    cd = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=256)
    is_deleted = models.CharField(max_length=1)
    date_format = models.CharField(max_length=100)
    boolean_format = models.CharField(max_length=100)
    decimal_format = models.CharField(max_length=100)
    output_type = models.CharField(max_length=1)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    created_by = models.ForeignKey(
        WorkspaceUser,
        related_name="created_channels",
        on_delete=models.DO_NOTHING,
        to_field="user_uid",
        db_column="created_by",
    )
    updated_by = models.ForeignKey(
        WorkspaceUser,
        related_name="updated_channels",
        on_delete=models.DO_NOTHING,
        to_field="user_uid",
        db_column="updated_by",
    )

    class Meta:
        managed = False
        db_table = "channels"
        UniqueConstraint(fields=["cd"], name="channel_unique")
        UniqueConstraint(fields=["name"], name="channel_unique_name")
