from datetime import datetime
from typing import Optional

from pydantic import BaseModel, constr
from sqlalchemy import Column, Integer, String, DateTime, Table, ForeignKey, UniqueConstraint
from sqlalchemy.orm import relationship, backref

from app.models.base_model import Base


class LabelModel(Base):
    __tablename__ = 'label'
    id = Column(Integer, primary_key=True, index=True)
    created_at = Column(DateTime, default=datetime.now())
    updated_at = Column(DateTime, default=datetime.now(), onupdate=datetime.now())
    name = Column(String(128), unique=True, nullable=False, index=True)
    status = Column(String(10), default="1")
    creator = Column(Integer)
    label_type = Column(Integer, default=1)

    def to_json(self):
        return {
            'labelId': self.id,
            'labelName': self.name,
            'labelType': self.label_type
        }


class LabelWorkerModel(Base):
    __tablename__ = 'label_worker'
    __table_args__ = (UniqueConstraint('label_id', 'object_id', name='label_object_id_ix'),)
    id = Column(Integer, primary_key=True, index=True)
    label_id = Column(Integer)
    object_id = Column(String(36))



class LabelData(BaseModel):
    labelName: str
    labelType: Optional[int] = 1


class SignLabelData(BaseModel):
    labelIdList: list
    objectId:str

