import datetime
from database import Base
from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float


class User(Base):
    __tablename__ = 'users'

    id = Column(Integer, primary_key=True)
    first_name = Column(String(255))
    last_name = Column(String(255))
    email = Column(String(255), index=True, unique=True)
    password = Column(String(255))

    def get_id(self):
        """
        Callback for Flask-Login. Represents that unique ID of a given user
        object. It is unicoded as per specification.

        Returns: the unique ID of an object
        """
        return unicode(self.id)

    def is_anonymous(self):
        """
        Callback for Flask-Login. Default to False - we don't deal with any
        anonymous users.

        Returns: False
        """
        return False

    def is_active(self):
        """
        Callback for Flask-Login. Default to True - we don't deal with
        non-active users.

        Returns: True
        """
        return True

    def is_authenticated(self):
        """
        Callback for Flask-Login. Should return True unless the object
        represents a user should not be authenticated.

        Returns: True because all objects should be authenticated
        """
        return True


class PendingTransaction(Base):
    __tablename__ = 'pending_transactions'

    id = Column(Integer, primary_key=True)
    barcode = Column(String(10))
    user_id = Column(Integer, ForeignKey('users.id'))
    timestamp = Column(DateTime, nullable=False, default=datetime.datetime.now())
    # Status: 0 - default, 1 - scanned, 2 - claimed
    status = Column(Integer, default=0)
    company = Column(Integer, ForeignKey('vendors.id'))
    amount = Column(Float)


class Transaction(Base):
    __tablename__ = 'transactions'

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey('users.id'))
    company = Column(Integer, ForeignKey('vendors.id'))
    amount = Column(Float)
    timestamp = Column(DateTime, nullable=False, default=datetime.datetime.now())

class Vendor(Base):
    __tablename__ = 'vendors'

    id = Column(Integer, primary_key=True)
    name = Column(String(255))
    agent_url = Column(String(255))
    secret = Column(String(255))

[((176, 209), 'sqlalchemy.Column', 'Column', (['Integer'], {'primary_key': '(True)'}), '(Integer, primary_key=True)\n', (182, 209), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1374, 1407), 'sqlalchemy.Column', 'Column', (['Integer'], {'primary_key': '(True)'}), '(Integer, primary_key=True)\n', (1380, 1407), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1642, 1668), 'sqlalchemy.Column', 'Column', (['Integer'], {'default': '(0)'}), '(Integer, default=0)\n', (1648, 1668), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1738, 1751), 'sqlalchemy.Column', 'Column', (['Float'], {}), '(Float)\n', (1744, 1751), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1824, 1857), 'sqlalchemy.Column', 'Column', (['Integer'], {'primary_key': '(True)'}), '(Integer, primary_key=True)\n', (1830, 1857), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1981, 1994), 'sqlalchemy.Column', 'Column', (['Float'], {}), '(Float)\n', (1987, 1994), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((2138, 2171), 'sqlalchemy.Column', 'Column', (['Integer'], {'primary_key': '(True)'}), '(Integer, primary_key=True)\n', (2144, 2171), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((234, 245), 'sqlalchemy.String', 'String', (['(255)'], {}), '(255)\n', (240, 245), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((270, 281), 'sqlalchemy.String', 'String', (['(255)'], {}), '(255)\n', (276, 281), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((302, 313), 'sqlalchemy.String', 'String', (['(255)'], {}), '(255)\n', (308, 313), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((362, 373), 'sqlalchemy.String', 'String', (['(255)'], {}), '(255)\n', (368, 373), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1429, 1439), 'sqlalchemy.String', 'String', (['(10)'], {}), '(10)\n', (1435, 1439), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1471, 1493), 'sqlalchemy.ForeignKey', 'ForeignKey', (['"""users.id"""'], {}), "('users.id')\n", (1481, 1493), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1699, 1723), 'sqlalchemy.ForeignKey', 'ForeignKey', (['"""vendors.id"""'], {}), "('vendors.id')\n", (1709, 1723), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1888, 1910), 'sqlalchemy.ForeignKey', 'ForeignKey', (['"""users.id"""'], {}), "('users.id')\n", (1898, 1910), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1942, 1966), 'sqlalchemy.ForeignKey', 'ForeignKey', (['"""vendors.id"""'], {}), "('vendors.id')\n", (1952, 1966), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((2190, 2201), 'sqlalchemy.String', 'String', (['(255)'], {}), '(255)\n', (2196, 2201), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((2226, 2237), 'sqlalchemy.String', 'String', (['(255)'], {}), '(255)\n', (2232, 2237), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((2259, 2270), 'sqlalchemy.String', 'String', (['(255)'], {}), '(255)\n', (2265, 2270), False, 'from sqlalchemy import Column, String, Integer, ForeignKey, DateTime, Float\n'), ((1552, 1575), 'datetime.datetime.now', 'datetime.datetime.now', ([], {}), '()\n', (1573, 1575), False, 'import datetime\n'), ((2052, 2075), 'datetime.datetime.now', 'datetime.datetime.now', ([], {}), '()\n', (2073, 2075), False, 'import datetime\n')]