#!/usr/bin/python3

from csv import unregister_dialect
#import email
from sqlite3 import Date
from xmlrpc.client import Boolean
from click import password_option
from pymysql import Time, Timestamp
#from ssl import _PasswordType
#from xmlrpc.client import DateTime
#from matplotlib.pyplot import title
from sqlalchemy import Column, Integer, Float, String, Text, DateTime, ForeignKey, BOOLEAN
from sqlalchemy.ext.declarative import declarative_base
#from sqlalchemy.orm import relationship
from sqlalchemy import func, create_engine,join
from config import CONFIG

Base = declarative_base()


class User(Base):
    __tablename__   = 'user'
    id              = Column(Integer, primary_key=True, autoincrement=True)
    username        = Column(String(64))
    password        = Column(String(64))
#    email           = Column(String)
#   config
#   deck_size       = Column(Integer)


class Card(Base):
    __tablename__   = 'card'
    id              = Column(Integer, primary_key=True, autoincrement=True)
    title           = Column(String(1024))
    owner_id        = Column(Integer, ForeignKey("user.id"), nullable=False)
    interest_rate   = Column(Float)
    item_location   = Column(String(1024))
    last_review     = Column(Text)
    share_id        = Column(Integer) #explain: 0 means not shared, otherwise increment from db and generate new cards for all relevant(tbd) users

class Deck(Base):
    __tablename__   = 'deck'
    id = Column(Integer, primary_key=True, autoincrement=True)
    owner_id = Column(Integer, ForeignKey("user.id"), nullable=False)
    cards_by_id = Column(Text)
    number_of_cards = Column(Integer) 
    current_card = Column(Integer)
    completed = Column(BOOLEAN)

"""
class Review(Base):
    __tablename__ = 'review'
    id = Column(Integer, primary_key=True, autoincrement=True)
    reviewer_id = Column(Integer, ForeignKey("user.id"), nullable=False)
    card_id = Column(Integer, ForeignKey("user.id"), nullable=False)
    review = Column(Text)
    time = Column(DateTime)
"""

engine = create_engine(CONFIG['DB_CONNECTION'])

Base.metadata.create_all(engine)
