from marshmallow import Schema, fields
from marshmallow.validate import Range, Length
from sqlalchemy import Column, Integer, Boolean, DateTime

from ..db import Base
from ..shared.models import StringTypes


# ---- Error-report


class ErrorReport(Base):
    __tablename__ = 'error_report'
    id = Column(Integer, primary_key=True)
    description = Column(StringTypes.LONG_STRING, nullable=False)
    time_stamp = Column(DateTime)
    status_code = Column(Integer)
    endpoint = Column(StringTypes.MEDIUM_STRING)
    solved = Column(Boolean, default=False)

    def __repr__(self):
        return f"<Error-report(id={self.id})>"


class ErrorReportSchema(Schema):
    id = fields.Integer(dump_only=True, required=True, validate=Range(min=1))
    description = fields.String(required=True, validate=Length(min=1))
    time_stamp = fields.DateTime()
    status_code = fields.Integer()
    endpoint = fields.String()
    solved = fields.Boolean()

[((300, 333), 'sqlalchemy.Column', 'Column', (['Integer'], {'primary_key': '(True)'}), '(Integer, primary_key=True)\n', (306, 333), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), ((352, 399), 'sqlalchemy.Column', 'Column', (['StringTypes.LONG_STRING'], {'nullable': '(False)'}), '(StringTypes.LONG_STRING, nullable=False)\n', (358, 399), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), ((417, 433), 'sqlalchemy.Column', 'Column', (['DateTime'], {}), '(DateTime)\n', (423, 433), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), ((452, 467), 'sqlalchemy.Column', 'Column', (['Integer'], {}), '(Integer)\n', (458, 467), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), ((483, 516), 'sqlalchemy.Column', 'Column', (['StringTypes.MEDIUM_STRING'], {}), '(StringTypes.MEDIUM_STRING)\n', (489, 516), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), ((530, 560), 'sqlalchemy.Column', 'Column', (['Boolean'], {'default': '(False)'}), '(Boolean, default=False)\n', (536, 560), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), ((834, 851), 'marshmallow.fields.DateTime', 'fields.DateTime', ([], {}), '()\n', (849, 851), False, 'from marshmallow import Schema, fields\n'), ((870, 886), 'marshmallow.fields.Integer', 'fields.Integer', ([], {}), '()\n', (884, 886), False, 'from marshmallow import Schema, fields\n'), ((902, 917), 'marshmallow.fields.String', 'fields.String', ([], {}), '()\n', (915, 917), False, 'from marshmallow import Schema, fields\n'), ((931, 947), 'marshmallow.fields.Boolean', 'fields.Boolean', ([], {}), '()\n', (945, 947), False, 'from marshmallow import Schema, fields\n'), ((732, 744), 'marshmallow.validate.Range', 'Range', ([], {'min': '(1)'}), '(min=1)\n', (737, 744), False, 'from marshmallow.validate import Range, Length\n'), ((802, 815), 'marshmallow.validate.Length', 'Length', ([], {'min': '(1)'}), '(min=1)\n', (808, 815), False, 'from marshmallow.validate import Range, Length\n')]