from pydantic import BaseModel,Field
from typing import List, Optional
from datetime import datetime

class KgSubGraphCreate(BaseModel):
    graph_name: str
    graph_content: str
    status :int
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict       

class KgSubGraph(KgSubGraphCreate):    
    id: int

    class Config:
        from_attributes = True
    
class KgPropCreate(BaseModel):
    category: int
    prop_name: str
    prop_value: str
    prop_title: str
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict       

class KgProp(KgPropCreate):
    id: int
    ref_id: int

    class Config:
        from_attributes = True
        
class KgNodeCreate(BaseModel):
    name: str
    category: str
    layout: Optional[str] = None
    version: Optional[str] = None
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict       

class KgNode(KgNodeCreate):
    id: int
    graph_id: int
    status: int
    props: List[KgProp]
    class Config:
        from_attributes = True

class KgNodeMerge(BaseModel):
    src_id: int
    dest_id: int

class KgEdgeCreate(BaseModel):
    graph_id: int
    category: str
    src_id: int
    dest_id: int
    name: str
    version: Optional[str] = None
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict       
    
    class Config:
        from_attributes = True

class KgEdge(KgEdgeCreate):
    id: int
    status: int
    src_node: KgNode
    dest_node: KgNode
    
    class Config:
        from_attributes = True
        
class KgEdgeName(BaseModel):
    category: str
    name: str
    
    class Config:
        from_attributes = True
        
        
class DictICD(BaseModel):
    id: int
    icd_code: str
    icd_name: str
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict   
        
    class Config:
        from_attributes = True


class DictDRG(BaseModel):
    id: int
    drg_code: str
    drg_name: str
    drg_weight: float
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict   
        
    class Config:
        from_attributes = True

class DictDrug(BaseModel):
    
    id: int
    data_source : str
    drug_code : str
    reg_name : str
    prod_name : str
    reg_dosage_form : str
    act_dosage_form : str
    reg_spec : str
    act_spec: str
    pkg_mat : str
    min_pack_size : str
    min_pack_unit : str
    min_dosage_unit : str
    prod_factory : str
    license_no : str
    drug_std_code: str
    subpkg_factory: str
    sales_status : str
    social_insurance_name : str
    jiayi_category : str
    social_dosage_form : str
    serial_no: str
    comments : str
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict   
        
    class Config:
        from_attributes = True
    

class KgSchemasCreate(BaseModel):
    name: str
    category: str
    content: str
    version: str
    
class KgSchemasUpdate(BaseModel):
    id:int
    name: str
    category: str
    content: str
    version: str

class KgSchemaSystems(BaseModel):
    schema_system:str
    class Config:
        from_attributes = True
    
class KgSchemas(BaseModel):    
    id: int
    name: str
    schema_system: str
    schema_type: str
    category: str
    content: str
    version: Optional[str] = None
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict   
        
    class Config:
        from_attributes = True

class NLPRequest(BaseModel):
    category: str
    name: str
    content: str    


class KgProjCreate(BaseModel):    
    proj_name : str
    proj_category : str
    proj_type : str
    proj_conf : str
    
class KgProj(KgProjCreate):    
    id : int
    created : datetime
    updated : datetime
    status : int
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict   
    
    class Config:
        from_attributes = True

class KgTaskUpdate(BaseModel):
    id: int
    task_log: str

class KgTaskCreate(BaseModel):    
    proj_id : int
    task_category : str
    task_content : str
    task_name : Optional[str]
    
class KgTask(KgTaskCreate):    
    id : int
    task_log : Optional[str]
    created : datetime
    updated : datetime
    status : int
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict   
    
    class Config:
        from_attributes = True

class KgModels(BaseModel):
    id: int
    model_name: str
    model_category: str
    model_description: str
    model_settings: str
    created : datetime
    updated : datetime
    status : int
    
    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict   
    
    class Config:
        from_attributes = True

class KgGraphCreate(BaseModel):
    name: str
    category: str
    graph_description: str
    schema_id: int

class KgGraphs(BaseModel):
    id: int
    name: str
    category: str
    graph_description: str
    graph_settings: str
    created: datetime
    updated: datetime
    status: int

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict

    class Config:
        from_attributes = True


class KgDataset(BaseModel):
    id: int
    data_name: str
    data_category: str
    data_comments: str
    created: datetime
    updated: datetime
    status: int

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict

    class Config:
        from_attributes = True
__all__=['KgSchemaSystems','NLPRequest','KgNodeMerge','KgNode','KgNodeCreate',
         'KgEdge','KgEdgeCreate','KgProp','KgPropCreate','DictICD','DictDRG','DictDrug',
         'KgSchemas','KgSchemasCreate','KgSchemasUpdate','KgEdgeName',
         'KgSubGraphCreate','KgSubGraph','KgModels','KgGraphs','KgGraphCreate',
         'KgDataset']