# Database Models
from . import db # that SQLAlchemy Object in __init__.py
from flask_login import UserMixin
from sqlalchemy.sql import func

class User(db.Model, UserMixin): # User Database
   id = db.Column(db.Integer, primary_key=True)
   email = db.Column(db.String(150), unique=True)
   password = db.Column(db.String(150))
   username = db.Column(db.String(150))
   profile_image = db.Column(db.String(150))

class TX(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    filehash = db.Column(db.String(64)) # sha256 hash
    datetime = db.Column(db.DateTime(timezone=True))
    source_id = db.Column(db.Integer)
    destination_id = db.Column(db.Integer)
    price = db.Column(db.Float)
    txhash = db.Column(db.String(64))

class Hashchain(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    blockhash = db.Column(db.String(64))

class Art(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200))
    description = db.Column(db.String(200))
    filehash = db.Column(db.String(64)) # sha256 hash
    owner = db.Column(db.Integer)
    creator = db.Column(db.Integer)
    dname = db.Column(db.String(20))

class List(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    filehash = db.Column(db.String(64)) # sha256 hash
    seller = db.Column(db.Integer)
    min_price = db.Column(db.Float)
    out_price = db.Column(db.Float)
    timeout = db.Column(db.String(20))
    list_date = db.Column(db.DateTime(timezone=True), default=func.now()) 

class Bids(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    filehash = db.Column(db.String(64)) # sha256 hash
    buyer = db.Column(db.Integer)
    bid_price = db.Column(db.Float)
    bid_date = db.Column(db.DateTime(timezone=True), default=func.now()) 
