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()

[(14, 'sqlalchemy.Column', 'Column', (['Integer'], {'primary_key': '(True)'}), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), (15, 'sqlalchemy.Column', 'Column', (['StringTypes.LONG_STRING'], {'nullable': '(False)'}), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), (16, 'sqlalchemy.Column', 'Column', (['DateTime'], {}), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), (17, 'sqlalchemy.Column', 'Column', (['Integer'], {}), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), (18, 'sqlalchemy.Column', 'Column', (['StringTypes.MEDIUM_STRING'], {}), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), (19, 'sqlalchemy.Column', 'Column', (['Boolean'], {'default': '(False)'}), False, 'from sqlalchemy import Column, Integer, Boolean, DateTime\n'), (28, 'marshmallow.fields.DateTime', 'fields.DateTime', ([], {}), False, 'from marshmallow import Schema, fields\n'), (29, 'marshmallow.fields.Integer', 'fields.Integer', ([], {}), False, 'from marshmallow import Schema, fields\n'), (30, 'marshmallow.fields.String', 'fields.String', ([], {}), False, 'from marshmallow import Schema, fields\n'), (31, 'marshmallow.fields.Boolean', 'fields.Boolean', ([], {}), False, 'from marshmallow import Schema, fields\n'), (26, 'marshmallow.validate.Range', 'Range', ([], {'min': '(1)'}), False, 'from marshmallow.validate import Range, Length\n'), (27, 'marshmallow.validate.Length', 'Length', ([], {'min': '(1)'}), False, 'from marshmallow.validate import Range, Length\n')]