from pydantic import BaseModel
from datetime import datetime
import typing as t


class Base(BaseModel):
    create_time: datetime
    update_time: datetime

class UserBase(BaseModel):
    email: str
    is_active: bool = True
    is_superuser: bool = False
    first_name: str = None
    last_name: str = None


class UserOut(UserBase):
    pass


class UserCreate(UserBase):
    email:str
    password: str
    first_name: str
    last_name: str
    is_active:bool
    is_superuser:bool

    class Config:
        orm_mode = True


class UserEdit(UserBase):
    password: t.Optional[str] = None

    class Config:
        orm_mode = True


class User(UserBase):
    id: int

    class Config:
        orm_mode = True


class Token(BaseModel):
    access_token: str
    token_type: str


class TokenData(BaseModel):
    id:int = 0
    email: str = None
    permissions: str = "user"


class AppEdit(BaseModel):
    setting: str = None

class AppBase(BaseModel):
    appid: str
    setting: str = None


class App(AppBase):
    id: int

    class Config:
        orm_mode = True


class Kintone(BaseModel):
    id: int
    type: int
    name: str = None
    desc: str = None
    content: str = None

    class Config:
        orm_mode = True

class Action(BaseModel):
    id: int
    name: str = None
    title: str = None
    subtitle: str = None
    outputpoints: str = None
    property: str = None

    class Config:
        orm_mode = True

class FlowBase(BaseModel):
    flowid: str 
    appid: str 
    eventid: str
    name: str = None
    content: str = None

class Flow(Base):
    id: int
    flowid: str 
    appid: str 
    eventid: str
    domainid: int
    name: str = None
    content: str = None

    class Config:
        orm_mode = True

class DomainBase(BaseModel):
    id: int
    tenantid: str
    name: str 
    url: str
    kintoneuser: str 
    kintonepwd: str 

class Domain(Base):
    id: int
    tenantid: str
    name: str 
    url: str
    kintoneuser: str 
    kintonepwd: str 

    class Config:
        orm_mode = True

class Event(Base):
    id: int
    category: str
    type: str 
    eventid: str
    function: str 
    mobile: bool
    eventgroup: bool

    class Config:
        orm_mode = True

class ErrorCreate(BaseModel):
    title:str
    location:str
    content:str