from django.db import models

# Create your models here.
from django.contrib.auth.models import User  # Assuming you're using Django's built-in User model

class Report(models.Model):
    name = models.CharField(max_length=255)  # Name of the report
    created_by = models.ForeignKey(
        User,
        on_delete=models.CASCADE,
        related_name="reports"
    )  # Reference to the user who created the report
    created_at = models.DateTimeField(auto_now_add=True)  # Automatically set when created
    updated_at = models.DateTimeField(auto_now=True)  # Automatically updated when modified
    file = models.FileField(upload_to='reports/files/', null=True, blank=True)  # File field
    
    def __str__(self):
        return self.name


class MgMasterView(models.Model):
    # ProcessControl.dbo.[Q-PRO-DATA]
    PRO0 = models.CharField(primary_key=True,max_length=255, null=False)
    PRO1 = models.CharField(max_length=255, null=True)
    PRO1C = models.CharField(max_length=255, null=True)
    Japanese_CustomerName = models.CharField(max_length=255, null=True)
    PRO2 = models.CharField(max_length=255, null=True)
    PRO5 = models.CharField(max_length=255, null=True)
    PRO8 = models.CharField(max_length=255, null=True)
    PRO9 = models.CharField(max_length=255, null=True)
    PRO10 = models.CharField(max_length=255, null=True)
    PRO11 = models.CharField(max_length=255, null=True)
    PRO12 = models.CharField(max_length=255, null=True)
    PRO13 = models.CharField(max_length=255, null=True)
    PRO14 = models.CharField(max_length=255, null=True)
    PRO15 = models.CharField(max_length=255, null=True)
    PRO16 = models.CharField(max_length=255, null=True)
    PRO17 = models.CharField(max_length=255, null=True)
    PRO18 = models.CharField(max_length=255, null=True)
    PRO21 = models.CharField(max_length=255, null=True)
    PRO25 = models.CharField(max_length=255, null=True)
    PRO27 = models.CharField(max_length=255, null=True)
    P2 = models.CharField(max_length=255, null=True)  # PRO-P2
    SPEED = models.CharField(max_length=255, null=True)  # PRO-SPEED
    PRO_TOOL = models.CharField(max_length=255, null=True,  db_column='PRO-TOOL')  # PRO-TOOL
    PRO4 = models.CharField(max_length=255, null=True)
    
    # dbo.[MG-MAS-1]
    MC11 = models.CharField(max_length=255, null=True)
    MC12 = models.CharField(max_length=255, null=True)
    MC14 = models.CharField(max_length=255, null=True)
    MC15 = models.CharField(max_length=255, null=True)
    MC16 = models.CharField(max_length=255, null=True)
    MC19 = models.CharField(max_length=255, null=True)
    MC20 = models.CharField(max_length=255, null=True)
    MC21 = models.CharField(max_length=255, null=True)
    MC22 = models.CharField(max_length=255, null=True)
    MC23 = models.CharField(max_length=255, null=True)
    MC24 = models.CharField(max_length=255, null=True)
    
    # dbo.[MG-MAS-2]
    MP45 = models.CharField(max_length=255, null=True)
    MP49 = models.CharField(max_length=255, null=True)
    
    # dbo.[MG-MAS-3]
    MI13 = models.CharField(max_length=255, null=True)
    TC = models.CharField(max_length=255, null=True)
    MI14 = models.CharField(max_length=255, null=True)
    MI15 = models.CharField(max_length=255, null=True)
    MI16 = models.CharField(max_length=255, null=True)
    MI17 = models.CharField(max_length=255, null=True)
    MI18 = models.CharField(max_length=255, null=True)
    MI19 = models.CharField(max_length=255, null=True)
    MI20 = models.CharField(max_length=255, null=True)
    MI21 = models.CharField(max_length=255, null=True)
    MI22 = models.CharField(max_length=255, null=True)
    MI23 = models.CharField(max_length=255, null=True)
    MI31 = models.CharField(max_length=255, null=True)
    MI33 = models.CharField(max_length=255, null=True)
    INSAGM = models.CharField(max_length=255, null=True)
    MARAGM = models.CharField(max_length=255, null=True)
    MI53 = models.CharField(max_length=255, null=True)
    MI55 = models.CharField(max_length=255, null=True)
    MI36 = models.CharField(max_length=255, null=True)
    MI39 = models.CharField(max_length=255, null=True)
    MI24 = models.CharField(max_length=255, null=True)
    
    # MGT_Config.dbo.[TABLE_TI-T1], [TABLE_TI-T5], [TABLE_TI-T6]
    Ind1 = models.CharField(max_length=255, null=True)  # TIT1NE
    Ind2 = models.CharField(max_length=255, null=True)  # TIT5NE
    Ind3 = models.CharField(max_length=255, null=True)  # TIT6NE
    
    # Conditional Fields
    AGR1 = models.CharField(max_length=255, null=True)
    AGR2 = models.CharField(max_length=255, null=True)
    ob_Condition = models.CharField(max_length=255, null=True)  # TIT4NE

    class Meta:
        managed = False
        db_table = 'mg_master_view'
        app_label = "legacy"
        #db_table = 'MgMasterView_Full_Mockup_Data'

class VMasterView(models.Model):
    # Fields from ProcessControl.dbo.[Q-PRO-DATA]
    PRO0 = models.CharField(primary_key=True, max_length=255, null=False)
    PRO1 = models.CharField(max_length=255, null=True)
    PRO1C = models.CharField(max_length=255, null=True)
    Japanese_CustomerName = models.CharField(max_length=255, null=True)
    PRO2 = models.CharField(max_length=255, null=True)
    PRO5 = models.CharField(max_length=255, null=True)
    PRO8 = models.CharField(max_length=255, null=True)
    PRO9 = models.CharField(max_length=255, null=True)
    PRO10 = models.CharField(max_length=255, null=True)
    PRO11 = models.CharField(max_length=255, null=True)
    PRO12 = models.CharField(max_length=255, null=True)
    PRO13 = models.CharField(max_length=255, null=True)
    PRO14 = models.CharField(max_length=255, null=True)
    PRO15 = models.CharField(max_length=255, null=True)
    PRO16 = models.CharField(max_length=255, null=True)
    PRO17 = models.CharField(max_length=255, null=True)
    PRO18 = models.CharField(max_length=255, null=True)
    PRO21 = models.CharField(max_length=255, null=True)
    PRO25 = models.CharField(max_length=255, null=True)
    PRO27 = models.CharField(max_length=255, null=True)
    P2 = models.CharField(max_length=255, null=True)  # PRO-P2
    PRO6 = models.CharField(max_length=255, null=True)
    SPEED = models.CharField(max_length=255, null=True)  # PRO-SPEED
    PRO_TOOL = models.CharField(max_length=255, null=True,  db_column='PRO-TOOL')  # PRO-TOOL
    PRO4 = models.CharField(max_length=255, null=True)
    
    # Fields from dbo.[V-MAS-1]
    MC11 = models.CharField(max_length=255, null=True)
    MC12 = models.CharField(max_length=255, null=True)
    MC14 = models.CharField(max_length=255, null=True)
    MC15 = models.CharField(max_length=255, null=True)
    MC16 = models.CharField(max_length=255, null=True)
    MC19 = models.CharField(max_length=255, null=True)
    MC20 = models.CharField(max_length=255, null=True)
    MC21 = models.CharField(max_length=255, null=True)
    MC22 = models.CharField(max_length=255, null=True)
    MC23 = models.CharField(max_length=255, null=True)
    MC24 = models.CharField(max_length=255, null=True)
    
    # Fields from dbo.[V-MAS-2]
    MP34 = models.CharField(max_length=255, null=True)
    MP39 = models.CharField(max_length=255, null=True)
    
    # Fields from dbo.[V-MAS-3]
    MI13 = models.CharField(max_length=255, null=True)
    TC = models.CharField(max_length=255, null=True)
    MI14 = models.CharField(max_length=255, null=True)
    MI15 = models.CharField(max_length=255, null=True)
    MI16 = models.CharField(max_length=255, null=True)
    MI17 = models.CharField(max_length=255, null=True)
    MI18 = models.CharField(max_length=255, null=True)
    MI19 = models.CharField(max_length=255, null=True)
    MI20 = models.CharField(max_length=255, null=True)
    MI21 = models.CharField(max_length=255, null=True)
    MI22 = models.CharField(max_length=255, null=True)
    MI23 = models.CharField(max_length=255, null=True)
    MI31 = models.CharField(max_length=255, null=True)
    MI33 = models.CharField(max_length=255, null=True)
    INSAGM = models.CharField(max_length=255, null=True)
    MARAGM = models.CharField(max_length=255, null=True)
    MI53 = models.CharField(max_length=255, null=True)
    MI55 = models.CharField(max_length=255, null=True)
    MI36 = models.CharField(max_length=255, null=True)
    MI39 = models.CharField(max_length=255, null=True)
    MI24 = models.CharField(max_length=255, null=True)
    
    # Fields from MGT_Config.dbo.[TABLE_TI-T1], [TABLE_TI-T5], [TABLE_TI-T6]
    Ind1 = models.CharField(max_length=255, null=True)  # TIT1NE
    Ind2 = models.CharField(max_length=255, null=True)  # TIT5NE
    Ind3 = models.CharField(max_length=255, null=True)  # TIT6NE
    
    # Conditional Fields
    AGR1 = models.CharField(max_length=255, null=True)
    AGR2 = models.CharField(max_length=255, null=True)
    ob_Condition = models.CharField(max_length=255, null=True)  # TIT4NE


    class Meta:
        managed = False
        #db_table = 'VMasterView_Full_Mockup_Data'
        db_table = 'v_master_view'
        app_label = "legacy"


class VwRotateLog(models.Model):
    # Fields from the SQL view
    PROD_CODE = models.CharField(max_length=255, null=True)
    LOT_NO = models.CharField(max_length=255, null=True)
    SPEED_SPEC = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    SPEED_TEST = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    SPEED_NG = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    CREATED_DT = models.DateTimeField(null=True)
    LAST_UPD_DT = models.DateTimeField(null=True)
    QTY = models.IntegerField(null=True)
    STATION_NO = models.CharField(max_length=255, null=True)

    class Meta:
        managed = False  # This model corresponds to a database view
        db_table = 'VwRotateLog_Mockup_Data'


class VwRotateResult(models.Model):
    # Fields from the SQL view
    PROD_CODE = models.CharField(max_length=255, null=True)
    LOT_NO = models.CharField(max_length=255, null=True)
    SPEED_SPEC = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    QTY = models.IntegerField(null=True)
    STATION_NO = models.CharField(max_length=255, null=True)
    START_DT = models.DateTimeField(null=True)  # T1.TEST_DT as START_DT
    TEST_NO = models.CharField(max_length=255, null=True)
    SPEED_TEST_VAL = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    SPEED_NG_VAL = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    TEST_END_DT = models.DateTimeField(null=True)  # T2.TEST_DT as TEST_END_DT

    class Meta:
        managed = False  # This model corresponds to a database view
        db_table = 'VW_ROTATE_RESULT'  # Name of the database view


class BelMasterView(models.Model):
    # Fields from ProcessControl.dbo.[Q-PRO-DATA]
    PRO0 = models.CharField(primary_key=True, max_length=255, null=False)
    PRO1 = models.CharField(max_length=255, null=True)
    PRO1C = models.CharField(max_length=255, null=True)
    Japanese_CustomerName = models.CharField(max_length=255, null=True)
    PRO2 = models.CharField(max_length=255, null=True)
    PRO5 = models.CharField(max_length=255, null=True)
    PRO8 = models.CharField(max_length=255, null=True)
    PRO9 = models.CharField(max_length=255, null=True)
    PRO10 = models.CharField(max_length=255, null=True)
    PRO11 = models.CharField(max_length=255, null=True)
    PRO12 = models.CharField(max_length=255, null=True)
    PRO13 = models.CharField(max_length=255, null=True)
    PRO14 = models.CharField(max_length=255, null=True)
    PRO15 = models.CharField(max_length=255, null=True)
    PRO16 = models.CharField(max_length=255, null=True)
    PRO17 = models.CharField(max_length=255, null=True)
    PRO18 = models.CharField(max_length=255, null=True)
    PRO21 = models.CharField(max_length=255, null=True)
    PRO25 = models.CharField(max_length=255, null=True)
    PRO27 = models.CharField(max_length=255, null=True)
    P2 = models.CharField(max_length=255, null=True)  # PRO-P2
    PRO6 = models.CharField(max_length=255, null=True)
    SPEED = models.CharField(max_length=255, null=True)  # PRO-SPEED
    PRO_TOOL = models.CharField(max_length=255, null=True,  db_column='PRO-TOOL')  # PRO-TOOL
    PRO4 = models.CharField(max_length=255, null=True)
    
    # Fields from dbo.[BEL-MAS-1]
    MC11 = models.CharField(max_length=255, null=True)
    MC12 = models.CharField(max_length=255, null=True)
    MC14 = models.CharField(max_length=255, null=True)
    MC15 = models.CharField(max_length=255, null=True)
    MC16 = models.CharField(max_length=255, null=True)
    MC19 = models.CharField(max_length=255, null=True)
    MC20 = models.CharField(max_length=255, null=True)
    MC21 = models.CharField(max_length=255, null=True)
    MC22 = models.CharField(max_length=255, null=True)
    MC23 = models.CharField(max_length=255, null=True)
    MC24 = models.CharField(max_length=255, null=True)
    
    # Fields from dbo.[BEL-MAS-2]
    MP45 = models.CharField(max_length=255, null=True)
    MP49 = models.CharField(max_length=255, null=True)
    
    # Fields from dbo.[BEL-MAS-3]
    MI13 = models.CharField(max_length=255, null=True)
    TC = models.CharField(max_length=255, null=True)
    MI14 = models.CharField(max_length=255, null=True)
    MI15 = models.CharField(max_length=255, null=True)
    MI16 = models.CharField(max_length=255, null=True)
    MI17 = models.CharField(max_length=255, null=True)
    MI18 = models.CharField(max_length=255, null=True)
    MI19 = models.CharField(max_length=255, null=True)
    MI20 = models.CharField(max_length=255, null=True)
    MI21 = models.CharField(max_length=255, null=True)
    MI22 = models.CharField(max_length=255, null=True)
    MI23 = models.CharField(max_length=255, null=True)
    MI31 = models.CharField(max_length=255, null=True)
    MI33 = models.CharField(max_length=255, null=True)
    INSAGM = models.CharField(max_length=255, null=True)
    MARAGM = models.CharField(max_length=255, null=True)
    MI53 = models.CharField(max_length=255, null=True)
    MI55 = models.CharField(max_length=255, null=True)
    MI36 = models.CharField(max_length=255, null=True)
    MI39 = models.CharField(max_length=255, null=True)
    MI24 = models.CharField(max_length=255, null=True)
    
    # Fields from MGT_Config.dbo.[TABLE_TI-T1], [TABLE_TI-T5], [TABLE_TI-T6]
    Ind1 = models.CharField(max_length=255, null=True)  # TIT1NE
    Ind2 = models.CharField(max_length=255, null=True)  # TIT5NE
    Ind3 = models.CharField(max_length=255, null=True)  # TIT6NE
    
    # Conditional Fields
    AGR1 = models.CharField(max_length=255, null=True)
    AGR2 = models.CharField(max_length=255, null=True)
    ob_Condition = models.CharField(max_length=255, null=True)  # TIT4NE

    class Meta:
        managed = False  # This model corresponds to a database view
        app_label = "legacy"
        db_table = 'bel_master_view'  # Name of the database view

class EMasterView(models.Model):
    # Fields from ProcessControl.dbo.[Q-PRO-DATA]
    PRO0 = models.CharField(primary_key=True, max_length=255, null=False)
    PRO1 = models.CharField(max_length=255, null=True)
    PRO1C = models.CharField(max_length=255, null=True)
    Japanese_CustomerName = models.CharField(max_length=255, null=True)
    PRO2 = models.CharField(max_length=255, null=True)
    PRO5 = models.CharField(max_length=255, null=True)
    PRO8 = models.CharField(max_length=255, null=True)
    PRO9 = models.CharField(max_length=255, null=True)
    PRO10 = models.CharField(max_length=255, null=True)
    PRO11 = models.CharField(max_length=255, null=True)
    PRO12 = models.CharField(max_length=255, null=True)
    PRO13 = models.CharField(max_length=255, null=True)
    PRO14 = models.CharField(max_length=255, null=True)
    PRO15 = models.CharField(max_length=255, null=True)
    PRO16 = models.CharField(max_length=255, null=True)
    PRO17 = models.CharField(max_length=255, null=True)
    PRO18 = models.CharField(max_length=255, null=True)
    PRO21 = models.CharField(max_length=255, null=True)
    PRO25 = models.CharField(max_length=255, null=True)
    PRO27 = models.CharField(max_length=255, null=True)
    P2 = models.CharField(max_length=255, null=True)  # PRO-P2
    PRO6 = models.CharField(max_length=255, null=True)
    SPEED = models.CharField(max_length=255, null=True)  # PRO-SPEED
    PRO_TOOL = models.CharField(max_length=255, null=True,  db_column='PRO-TOOL')  # PRO-TOOL
    PRO4 = models.CharField(max_length=255, null=True)
    
    # Fields from dbo.[E-MAS-1]
    MC11 = models.CharField(max_length=255, null=True)
    MC12 = models.CharField(max_length=255, null=True)
    MC14 = models.CharField(max_length=255, null=True)
    MC15 = models.CharField(max_length=255, null=True)
    MC16 = models.CharField(max_length=255, null=True)
    MC19 = models.CharField(max_length=255, null=True)
    MC20 = models.CharField(max_length=255, null=True)
    MC21 = models.CharField(max_length=255, null=True)
    MC22 = models.CharField(max_length=255, null=True)
    MC23 = models.CharField(max_length=255, null=True)
    MC24 = models.CharField(max_length=255, null=True)
    
    # Fields from dbo.[E-MAS-2]
    MP45 = models.CharField(max_length=255, null=True)
    MP49 = models.CharField(max_length=255, null=True)
    
    # Fields from dbo.[E-MAS-3]
    MI13 = models.CharField(max_length=255, null=True)
    TC = models.CharField(max_length=255, null=True)
    MI14 = models.CharField(max_length=255, null=True)
    MI15 = models.CharField(max_length=255, null=True)
    MI16 = models.CharField(max_length=255, null=True)
    MI17 = models.CharField(max_length=255, null=True)
    MI18 = models.CharField(max_length=255, null=True)
    MI19 = models.CharField(max_length=255, null=True)
    MI20 = models.CharField(max_length=255, null=True)
    MI21 = models.CharField(max_length=255, null=True)
    MI22 = models.CharField(max_length=255, null=True)
    MI23 = models.CharField(max_length=255, null=True)
    MI31 = models.CharField(max_length=255, null=True)
    MI33 = models.CharField(max_length=255, null=True)
    INSAGM = models.CharField(max_length=255, null=True)
    MARAGM = models.CharField(max_length=255, null=True)
    MI53 = models.CharField(max_length=255, null=True)
    MI55 = models.CharField(max_length=255, null=True)
    MI36 = models.CharField(max_length=255, null=True)
    MI39 = models.CharField(max_length=255, null=True)
    MI24 = models.CharField(max_length=255, null=True)
    
    # Fields from MGT_Config.dbo.[TABLE_TI-T1], [TABLE_TI-T5], [TABLE_TI-T6]
    Ind1 = models.CharField(max_length=255, null=True)  # TIT1NE
    Ind2 = models.CharField(max_length=255, null=True)  # TIT5NE
    Ind3 = models.CharField(max_length=255, null=True)  # TIT6NE
    
    # Conditional Fields
    AGR1 = models.CharField(max_length=255, null=True)
    AGR2 = models.CharField(max_length=255, null=True)
    ob_Condition = models.CharField(max_length=255, null=True)  # TIT4NE

    class Meta:
        managed = False  # This model corresponds to a database view
        app_label = "legacy"
        db_table = 'e_master_view'  # Name of the database view

class AllProductAverageObMinMaxView(models.Model):
    ProductCode = models.CharField(max_length=255, null=True)  # RE01
    out_min = models.DecimalField(max_digits=10, decimal_places=2, null=True)  # Minimum of [OB-O]
    out_max = models.DecimalField(max_digits=10, decimal_places=2, null=True)  # Maximum of [OB-O]
    in_min = models.DecimalField(max_digits=10, decimal_places=2, null=True)  # Minimum of [OB-I]
    in_max = models.DecimalField(max_digits=10, decimal_places=2, null=True)  # Maximum of [OB-I]

    class Meta:
        managed = False  # This model corresponds to a database view
        app_label = "legacy"
        db_table = 'AllProduct_Average_OB_MIN_MAX_view'  # Name of the database view

class AllProductDimensionForInsProcess(models.Model):
    ProdType = models.CharField(max_length=255, null=True)  # Product type (e.g., 'V', 'E', 'BEL', 'MG')
    ProductCode = models.CharField(max_length=255, primary_key=True) # Product code# Product code
    Size_Id = models.CharField(max_length=255, null=True)  # Size ID (e.g., '001', '002')
    Size_Name = models.CharField(max_length=255, null=True)  # Size name (e.g., 'D', 'T', 'H')
    Std = models.DecimalField(max_digits=10, decimal_places=2, null=True)  # Standard value
    TolUn = models.DecimalField(max_digits=10, decimal_places=2, null=True)  # Tolerance lower limit
    TolUp = models.DecimalField(max_digits=10, decimal_places=2, null=True)  # Tolerance upper limit

    class Meta:
        managed = False  # This model corresponds to a database view
        app_label = "legacy"
        db_table = 'AllProduct_Dimension_ForInsProcess'  # Name of the database view

class AllProductPressPositionPressWeight(models.Model):
    ProductCode = models.CharField(max_length=255, null=True)
    Lot_No = models.CharField(max_length=255, null=True)
    PO_Qty = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    UWeight = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    Current_ProNo = models.CharField(max_length=255, null=True)
    Press_Time = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    PressType_1 = models.CharField(max_length=255, null=True)
    PressWeight_1 = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    PressType_2 = models.CharField(max_length=255, null=True)
    PressWeight_2 = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    Press_Ton = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    Press_T = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    Press_T_Tol = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    Mold_D = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    Mold_T = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    SegMold_T = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    SegMold_D = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    Center_D = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    Center_T = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    LowerPlate_T = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    StudPlate_T = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    UpperPlate_T = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    PinPlate_T = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    TopConcave_T = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    BottomConcave_T = models.DecimalField(max_digits=10, decimal_places=2, null=True)

    class Meta:
        managed = False  # This model corresponds to a database view
        app_label = "legacy"
        db_table = 'AllProduct_PressPosition_PressWeight'  # Name of the database view

class RotateBrokenTest(models.Model):
    row_no = models.IntegerField(null=True, blank=True)
    speed_spec = models.FloatField(null=True, blank=True)
    speed_test = models.FloatField(null=True, blank=True)
    speedOk = models.CharField(max_length=4, null=True, blank=True)
    qty = models.IntegerField()
    station_no = models.IntegerField()
    created_at = models.DateTimeField(null=True, blank=True)
    updated_at = models.DateTimeField(null=True, blank=True)
    lot_no = models.CharField(max_length=50, null=True, blank=True)
    machine_id = models.IntegerField(null=True, blank=True)
    code = models.CharField(max_length=50, null=True, blank=True)
    emp_id = models.IntegerField()
    devid = models.CharField(max_length=40, null=True, blank=True)
    mode = models.CharField(max_length=10, null=True, blank=True)
    cal_mode = models.IntegerField(null=True, blank=True)

    class Meta:
        managed = False  # This model corresponds to a database view
        app_label = "legacy"
        db_table = "rotate_broken_test"  # Matches SQL Server table name

class LotType(models.Model):
    lot_no = models.CharField(primary_key=True,max_length=20, db_column='LotNo')
    group = models.CharField(max_length=10, db_column='Group')
    sub_group = models.CharField(max_length=10, db_column='SubGroup')

    class Meta:
        db_table = 'T-LotType'
        managed = False  # Since it's an existing table in SQL Server
        app_label = "trans"


TEMPLATE_CHOICES = [
    "hardness_out",
    "hardness_out_in",
    "hardness_both_size",
    "dimension",
    "dimension_app",
    "dimension_bal_weight",
    "dim_bal_app_hard",
    "dim_bal_app_rot_hard",
    "thickness_8_point",
    "centering"
]

class CustomerTemplateMapping(models.Model):
    TEMPLATE_TYPE_CHOICES = [
        ("japanese", "Japanese"),
        ("asean", "ASEAN"),
    ]

    customer_name = models.CharField(max_length=255)
    export_template = models.CharField(
        max_length=20,
        choices=TEMPLATE_TYPE_CHOICES,
        default="japanese",
    )
    template_names = models.JSONField(default=list, blank=True, null=True)  # stores list of template names

    created_by = models.ForeignKey(
        User,
        on_delete=models.SET_NULL,
        null=True,
        blank=True, 
    )  # Reference to the user who created the report
    created_at = models.DateTimeField(auto_now_add=True)  # Automatically set when created
    updated_at = models.DateTimeField(auto_now=True)  # Automatically updated when modified
    def __str__(self):
        return self.customer_name

class ProductDrawing(models.Model):
    code_no = models.CharField(max_length=100, null=True, blank=True)
    code_no_mks = models.CharField(max_length=100, null=True, blank=True)
    lot_no = models.CharField(max_length=100, null=True, blank=True)
    drawing = models.ImageField(upload_to='drawings/')
    description = models.TextField(null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    created_by = models.ForeignKey(
        User,
        on_delete=models.SET_NULL,
        null=True,
        blank=True, 
    )  # Reference to the user who created the report
    
    def __str__(self):
        return f"{self.code_no} - {self.lot_no}"

class MksCodeMap(models.Model):
    mgt_code = models.CharField(max_length=100)
    mks_code = models.CharField(max_length=100)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f"{self.mgt_code} ⇄ {self.mks_code}"
