from sqlalchemy import Column, Integer, String, BigInteger, SmallInteger, Boolean, DateTime, ForeignKey, Float, VARBINARY, Table, Unicode
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class Subject(Base):
    __tablename__ = 'subject'

    id = Column(BigInteger, primary_key=True, nullable=False, index=True)
    state = Column(Integer, index=True, nullable=True)
    moob = Column(Integer, nullable=True)
    daob = Column(Integer, nullable=True)
    yrob = Column(Integer, nullable=True)
    morel = Column(Integer, nullable=True)
    darel = Column(Integer, nullable=True)
    yrrel = Column(Integer, nullable=True)


class Arrestx(Base):
    __tablename__ = 'arrestx'

    id = Column(BigInteger, primary_key=True, nullable=False, index=True)
    casenum = Column(BigInteger, ForeignKey('subject.id'), nullable=False, index=True)
    casenumx = Column(String, nullable=False)
    rectype = Column(String, nullable=False)
    arrstatex = Column(String, nullable=True)
    astate = Column(Integer, nullable=True, index=True)
    rapstatex = Column(String, nullable=True)
    asource = Column(Integer, nullable=True)
    ynfederalx = Column(String, nullable=True)
    afed = Column(Integer, nullable=True)
    cycnumx = Column(String, nullable=True)
    cycnum = Column(Integer, nullable=True)
    aseqnumx = Column(String, nullable=True)
    seqnum = Column(Integer, nullable=True)
    arrdatex = Column(String, nullable=True)
    arrname = Column(String, nullable=True)
    arrnamex = Column(String, nullable=True)
    aori_invalid = Column(SmallInteger, nullable=True)
    aorix = Column(String, nullable=True)
    arrdatex = Column(String, nullable=True)
    aori = Column(String, nullable=True)
    offdatex = Column(String, nullable=True)
    arrtypex = Column(String, nullable=True)
    astatnumx = Column(String, nullable=True)
    achglitx = Column(String, nullable=True)
    achgdetx = Column(String, nullable=True)
    achgncicx = Column(String, nullable=True)
    aoffcodex = Column(String, nullable=True)
    achgsvrx = Column(String, nullable=True)
    atrknumx = Column(String, nullable=True)
    aincx = Column(String, nullable=True)
    arrcefx = Column(String, nullable=True)
    achgcntx = Column(String, nullable=True)
    aactlitx = Column(String, nullable=True)
    adispdatex = Column(String, nullable=True)
    adisptextx = Column(String, nullable=True)
    adisptypex = Column(String, nullable=True)
    eventdate1x = Column(String, nullable=True)

    subject = relationship("Subject", order_by='Arrest.id', backref='Arrest')


class Arrest(Base):
    __tablename__ = 'arrest'

    id = Column(BigInteger, ForeignKey('arrestx.id'), primary_key=True, nullable=False, index=True)
    casenum = Column(BigInteger, ForeignKey('subject.id'), nullable=False, index=True)
    rectype = Column(Integer, nullable=False)
    nonarr = Column(Integer, nullable=True)
    astate = Column(Integer, nullable=True, index=True)
    asource = Column(Integer, nullable=True)
    afed = Column(Integer, nullable=True)
    cycnum = Column(Integer, nullable=True)
    aseqnum = Column(Integer, nullable=True)
    arryr = Column(Integer, nullable=True)
    arrmo = Column(Integer, nullable=True)
    arrda = Column(Integer, nullable=True)
    arrname = Column(String, nullable=True)
    aori_invalid = Column(SmallInteger, nullable=True)
    aori = Column(String, nullable=True)
    offyr = Column(Integer, nullable=True)
    offmo = Column(Integer, nullable=True)
    offda = Column(Integer, nullable=True)
    atype = Column(Integer, nullable=True)
    achglit = Column(String, nullable=True)
    achgdet = Column(String, nullable=True)
    achgncic = Column(String, nullable=True)
    aoffcode = Column(String, nullable=True)
    ancic = Column(Integer, nullable=True)
    achg = Column(Integer, nullable=True)
    achg16 = Column(Integer, nullable=True)
    achgsvr = Column(Integer, nullable=True)
    ainc = Column(Integer, nullable=True)
    adom = Column(Integer, nullable=True)
    aweap = Column(Integer, nullable=True)
    acdv = Column(Integer, nullable=True)
    apg = Column(Integer, nullable=True)
    acnt = Column(Integer, nullable=True)
    adisptextx = Column(String, nullable=True)
    adsp = Column(Integer, nullable=True)

    arrestx = relationship("Arrestx", order_by='Arrest.id', backref='Arrest')
    subject = relationship("Subject", order_by='Arrest.id', backref='Arrest')


class ArrestPredict(Base):
    __tablename__ = 'arrest_predict'

    arrest_predict_id = Column(BigInteger, primary_key=True, nullable=False)
    arrest_id = Column(Integer, ForeignKey('arrest.id'), nullable=False, index=True)
    var_name = Column(String(20), nullable=False)
    prediction = Column(Integer, nullable=True)

    arrest = relationship("Arrest", order_by='ArrestPredict.arrest_predict_id', backref='ArrestPredict')


class Sentence(Base):
    __tablename__ = 'sentence'
    id = Column(BigInteger, ForeignKey('sentencex.id'), primary_key=True, nullable=False, index=True)
    casenum = Column(BigInteger, ForeignKey('subject.id'), nullable=False, index=True)
    rectype = Column(Integer, nullable=False)
    cstate = Column(Integer, nullable=True, index=True)
    csource = Column(Integer, nullable=True)
    cfed = Column(Integer, nullable=True)
    cycnum = Column(Integer, nullable=True)
    cseqnum = Column(Integer, nullable=True)
    cchglit = Column(String, nullable=True)
    cchgdet = Column(String, nullable=True)
    cchgncic = Column(String, nullable=True)
    coffcode = Column(String, nullable=True)
    cncic = Column(Integer, nullable=True)
    cchg = Column(Integer, nullable=True)
    cchg16 = Column(Integer, nullable=True)
    cchgsvr = Column(Integer, nullable=True)
    cinc = Column(Integer, nullable=True)
    cdom = Column(Integer, nullable=True)
    cweap = Column(Integer, nullable=True)
    cpg = Column(Integer, nullable=True)
    ccdv = Column(Integer, nullable=True)
    ccnt = Column(Integer, nullable=True)
    cdispyr = Column(Integer, nullable=True)
    cdispmo = Column(Integer, nullable=True)
    cdispda = Column(Integer, nullable=True)
    cdisptextx = Column(String, nullable=True)
    cdsp = Column(Integer, nullable=True)
    sntdatex = Column(String, nullable=True)
    sntyr = Column(Integer, nullable=True)
    sntmo = Column(Integer, nullable=True)
    sntda = Column(Integer, nullable=True)
    cnf = Column(Integer, nullable=True)
    trt = Column(Integer, nullable=True)
    oth = Column(Integer, nullable=True)
    cmsrv = Column(Float(precision=2, asdecimal=True), nullable=True)
    incmin = Column(Float(precision=2, asdecimal=True), nullable=True)
    incmax = Column(Float(precision=2, asdecimal=True), nullable=True)
    susp = Column(Float(precision=2, asdecimal=True), nullable=True)
    suspmin = Column(Float(precision=2, asdecimal=True), nullable=True)
    suspmax = Column(Float(precision=2, asdecimal=True), nullable=True)
    suspfine = Column(Float(precision=2, asdecimal=True), nullable=True)
    prb = Column(Float(precision=2, asdecimal=True), nullable=True)
    costs = Column(Float(precision=2, asdecimal=True), nullable=True)
    fineamt = Column(Float(precision=2, asdecimal=True), nullable=True)
    rst = Column(Float(precision=2, asdecimal=True), nullable=True)
    cori_invalid = Column(SmallInteger, nullable=True)
    cori = Column(String, nullable=True)
    noncrt = Column(Integer, nullable=True)
    pjp = Column(Integer, nullable=True)

    sentencex = relationship("Sentencex", order_by='Sentence.id', backref='Sentence')
    subject = relationship("Subject", order_by='Sentence.id', backref='Sentence')


class Sentencex(Base):
    __tablename__ = 'sentencex'

    id = Column(BigInteger, primary_key=True, nullable=False, index=True)
    casenum = Column(BigInteger, ForeignKey('subject.id'), nullable=False, index=True)
    casenumx = Column(String, nullable=False)
    rectype = Column(String, nullable=False)
    crtstatex = Column(String, nullable=True)
    cstate = Column(Integer, nullable=True, index=True)
    rapstatex = Column(String, nullable=True)
    csource = Column(Integer, nullable=True)
    ynfederalx = Column(String, nullable=True)
    cfed = Column(Integer, nullable=True)
    cycnumx = Column(String, nullable=True)
    cycnum = Column(Integer, nullable=True)
    cseqnumx = Column(String, nullable=True)
    seqnum = Column(Integer, nullable=True)
    crtcmtx = Column(String, nullable=True)
    cstatnumx = Column(String, nullable=True)
    cchglitx = Column(String, nullable=True)
    cchgdetx = Column(String, nullable=True)
    cchgncicx = Column(String, nullable=True)
    coffcodex = Column(String, nullable=True)
    cchgsvrx = Column(String, nullable=True)
    ctrknumx = Column(String, nullable=True)
    cincx = Column(String, nullable=True)
    crtcrfx = Column(String, nullable=True)
    crtcefx = Column(String, nullable=True)
    cchgcntx = Column(String, nullable=True)
    cactlitx = Column(String, nullable=True)
    cdispdatex = Column(String, nullable=True)
    cdisptextx = Column(String, nullable=True)
    cdisptypex = Column(String, nullable=True)
    sntdatex = Column(String, nullable=True)
    fdispdatex = Column(String, nullable=True)
    snttext = Column(String, nullable=True)
    cnflngx = Column(String, nullable=True)
    cnflngminx = Column(String, nullable=True)
    cnflngmaxx = Column(String, nullable=True)
    susplngx = Column(String, nullable=True)
    suspminx = Column(String, nullable=True)
    suspmaxx = Column(String, nullable=True)
    problingx = Column(String, nullable=True)
    probminx = Column(String, nullable=True)
    probmaxx = Column(String, nullable=True)
    courcostsx = Column(String, nullable=True)
    finex = Column(String, nullable=True)
    restitutionx = Column(String, nullable=True)
    crtnamex = Column(String, nullable=True)
    cori = Column(String, nullable=True)
    corix = Column(String, nullable=True)
    cori_invalid = Column(String, nullable=True)
    eventdate1x = Column(String, nullable=True)

    subject = relationship("Subject", order_by='Sentence.id', backref='Sentence')


class SentencePredict(Base):
    __tablename__ = 'sentence_predict'

    setence_predict_id = Column(BigInteger, primary_key=True, nullable=False)
    sentence_id = Column(Integer, ForeignKey('sentence.id'), nullable=False, index=True)
    var_name = Column(String(20), nullable=False)
    prediction = Column(Integer, nullable=True)

    sentence = relationship("Sentence", order_by='SentencePredict.sentence_predict_id', backref='SentencePredict')
