from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.dialects.postgresql import BYTEA
from datetime import datetime
import uuid

import Models
from app import db


class ImageModel(Models.Base):
    __tablename__ = "image"

    id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow())
    data = db.Column(BYTEA(), nullable=False)
    uploader_id = db.Column(db.ForeignKey('user.id'), nullable=True)
    uploader = db.relationship(
        "UserModel",
        foreign_keys=uploader_id
    )

    def __init__(self, **kwargs):
        self.date = datetime.utcnow()
        super().__init__(**kwargs)
