from django.db import models
from django.db.models.constraints import UniqueConstraint
import ulid

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 PCLItemDefVModel(models.Model):
    pid_sdc_cd = ULIDField(primary_key=True)
    pid_stc_cd = ULIDField()
    pid_ssc_cd = ULIDField()
    pid_slc_cd = ULIDField()
    pid_item_no = ULIDField()
    pid_del = models.CharField(max_length=1)
    pid_fix_item_flg = models.CharField(max_length=1)
    pid_cmn_item_flg = models.CharField(max_length=1)
    pid_order = models.IntegerField()
    pid_label = models.CharField(max_length=256)
    pid_ctrl = models.CharField(max_length=1)
    pid_nn = models.CharField(max_length=1)
    pid_max_len = models.IntegerField(default=0)
    pid_sel_list = models.CharField(max_length=1024)
    pid_df_val = models.CharField(max_length=1024)
    pid_df_unit = models.CharField(max_length=256)
    pid_op1 = models.CharField(max_length=32)
    pid_op2 = models.CharField(max_length=32)
    pid_op3 = models.CharField(max_length=32)
    atr_name = models.CharField(max_length=256)
    atr_unit = models.CharField(max_length=1)

    class Meta:
        managed = False
        db_table = 'pcl_item_def_v'
        UniqueConstraint(fields=['pid_sdc_cd','pid_stc_cd','pid_ssc_cd','pid_slc_cd','pid_item_no'], name='sku_tyu_ctgry_unique')
