from sqlalchemy import Column, ForeignKey, MetaData, Table
from sqlalchemy.sql.sqltypes import Boolean, Date, Integer, Numeric, Text

meta = MetaData()

schema = [
    Table(
        "subjekty",
        meta,
        Column("ico", Integer, nullable=False, primary_key=True, autoincrement=False),
        Column("nazev", Text, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
    ),
    Table(
        "spisova_znacka",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("znacka", Text, nullable=False),
        Column("soud_kod", Text, nullable=True),
        Column("soud_nazev", Text, nullable=True),
        Column("oddil", Text, nullable=True),
        Column("vlozka", Text, nullable=True),
    ),
    Table(
        "nazev",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("udaj_typ", Text, nullable=False),
        Column("nazev", Text, nullable=True),
    ),
    Table(
        "pravni_forma",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("nazev", Text, nullable=False),
        Column("zkratka", Text, nullable=False),
    ),
    Table(
        "predmet_podnikani",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("kategorie", Text, nullable=False),
        Column("text", Text, nullable=True),
    ),
    Table(
        "pocet_clenu",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("udaj_typ", Text, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("text", Text, nullable=True),
        Column("datum_vymaz", Date, nullable=True),
    ),
    Table(
        "zpusob_jednani",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=True),
    ),
    Table(
        "ostatni_skutecnosti",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=True),
    ),
    Table(
        "zpusob_rizeni",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=False),
    ),
    Table(
        "akcie",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("podoba", Text, nullable=True),
        Column("udaj_typ", Text, nullable=True),
        Column("pocet", Text, nullable=True),
        Column("hodnota_typ", Text, nullable=True),
        Column("hodnota", Numeric(16, 2), nullable=True),
        Column("text", Text, nullable=True),
    ),
    Table(
        "vklady",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("typ", Text, nullable=True),
        Column("vklad_typ", Text, nullable=True),
        Column("vklad_hodnota", Text, nullable=True),  # -- obcas tam je pitomost
        Column("text", Text, nullable=True),
    ),
    Table(
        "pravni_duvod_vymazu",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=False),
    ),
    Table(
        "spolecny_text",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("udaj_typ", Text, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("text", Text, nullable=True),
        Column("datum_vymaz", Date, nullable=True),
    ),
    Table(
        "exekuce",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=True),
    ),
    Table(
        "pravni_forma_text",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=True),
    ),
    Table(
        "nejvyssi_organ",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=True),
    ),
    Table(
        "vznik",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("datum_vznik", Date, nullable=False),
    ),
    Table(
        "majetek",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=False),
    ),
    Table(
        "spolecnik_zastavni_pravo",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("datum_vznik_prava", Text, nullable=True),  # -- obcas tam je pitomost
        Column("text", Text, nullable=True),
    ),
    Table(
        "text_spravni_rada",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=True),
    ),
    Table(
        "spolecnik_podil",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("vklad_typ", Text, nullable=True),
        Column("vklad_hodnota", Text, nullable=True),  # -- obcas tam je pitomost
        Column("souhrn_typ", Text, nullable=True),
        Column("souhrn_hodnota", Text, nullable=True),  # -- obcas tam je pitomost
        Column("splaceni_typ", Text, nullable=True),
        Column("splaceni_hodnota", Text, nullable=True),  # -- obcas tam je pitomost
        Column("druh_podilu", Text, nullable=True),
        Column("kmenovy_list", Text, nullable=True),
    ),
    Table(
        "sidlo",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("udaj_typ", Text, nullable=False),
        Column("stat", Text, nullable=True),
        Column("adresa", Text, nullable=True),
        Column("obec", Text, nullable=True),
        Column("cast_obce", Text, nullable=True),
        Column("ulice", Text, nullable=True),
        Column("cislo_po", Text, nullable=True),
        Column("cislo_or", Text, nullable=True),
        Column("cislo_text", Text, nullable=True),
        Column("psc", Text, nullable=True),
        Column("okres", Text, nullable=True),
    ),
    Table(
        "konkurs_prohlaseni",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("datum_rozhodnuti", Date, nullable=True),
        Column("spisova_znacka", Text, nullable=True),
        Column("datum_vyveseni", Date, nullable=True),
        Column("text", Text, nullable=True),
    ),
    Table(
        "konkurs_zruseni",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=False),
    ),
    Table(
        "skutecny_majitel",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("autoprupis", Boolean, nullable=False),
        Column("postaveni", Text, nullable=False),
        Column("skutecnym_majitelem_od", Date, nullable=True),
        Column("koncovy_prijemce_text", Text, nullable=True),
        Column("pozice_spravni_organ", Text, nullable=True),
        Column("vlastni_podil_na_prospechu", Boolean, nullable=True),
        Column("podil_na_prospechu_typ", Text, nullable=True),
        Column("podil_na_prospechu_hodnota", Numeric, nullable=True),
        Column("vlastni_podil_na_hlasovani", Boolean, nullable=True),
        Column("podil_na_hlasovani_typ", Text, nullable=True),
        Column("podil_na_hlasovani_hodnota", Numeric, nullable=True),
        Column("osoba_jmeno", Text, nullable=True),
        Column("osoba_prijmeni", Text, nullable=True),
        Column("osoba_datum_narozeni", Date, nullable=True),
        Column("osoba_titul_pred", Text, nullable=True),
        Column("osoba_titul_za", Text, nullable=True),
        Column("adresa_stat_nazev", Text, nullable=True),
        Column("adresa_obec", Text, nullable=True),
        Column("adresa_cast_obce", Text, nullable=True),
        Column("adresa_ulice", Text, nullable=True),
        Column("adresa_cislo_po", Text, nullable=True),
        Column("adresa_cislo_or", Text, nullable=True),
        Column("adresa_psc", Text, nullable=True),
        Column("adresa_okres", Text, nullable=True),
        Column("adresa_cislo_ev", Text, nullable=True),
        Column("adresa_text", Text, nullable=True),
        Column("bydliste_stat_nazev", Text, nullable=True),
        Column("bydliste_obec", Text, nullable=True),
        Column("bydliste_cast_obce", Text, nullable=True),
        Column("bydliste_cislo_po", Text, nullable=True),
        Column("bydliste_cislo_or", Text, nullable=True),
        Column("bydliste_psc", Text, nullable=True),
        Column("bydliste_ulice", Text, nullable=True),
    ),
    Table(
        "insolvencni_zapis",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("id", Text, nullable=True),
        Column("aktivni", Text, nullable=True),
        Column("key", Text, nullable=True),
        Column("nazev", Text, nullable=True),
        Column("externi_kod", Text, nullable=True),
        Column("text", Text, nullable=True),
    ),
    Table(
        "vyrovnani",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("udaj_typ", Text, nullable=False),
        Column("text", Text, nullable=True),
    ),
    Table(
        "angazovane_osoby",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("udaj_typ", Text, nullable=False),
        Column("funkce", Text, nullable=True),
        Column("funkce_od", Date, nullable=True),
        Column("clenstvi_od", Date, nullable=True),
        Column("clenstvi_do", Date, nullable=True),
        Column("funkce_do", Date, nullable=True),
        Column("jmeno", Text, nullable=True),
        Column("prijmeni", Text, nullable=True),
        Column("titul_pred", Text, nullable=True),
        Column("titul_za", Text, nullable=True),
        Column("datum_narozeni", Date, nullable=True),
        Column("nazev", Text, nullable=True),
        Column("reg_cislo", Text, nullable=True),
        Column("ico_angos", Integer, nullable=True),
        Column("euid", Text, nullable=True),
        Column("adresa_stat", Text, nullable=True),
        Column("adresa_obec", Text, nullable=True),
        Column("adresa_cast_obce", Text, nullable=True),
        Column("adresa_ulice", Text, nullable=True),
        Column("adresa_cislo_po", Text, nullable=True),
        Column("adresa_psc", Text, nullable=True),
        Column("adresa_okres", Text, nullable=True),
        Column("adresa_cislo_or", Text, nullable=True),
        Column("adresa_adresa_text", Text, nullable=True),
        Column("adresa_cislo_ev", Text, nullable=True),
        Column("adresa_doplnujici_text", Text, nullable=True),
        Column("adresa_cislo_text", Text, nullable=True),
        Column("bydliste_stat", Text, nullable=True),
        Column("bydliste_ulice", Text, nullable=True),
        Column("bydliste_obec", Text, nullable=True),
        Column("bydliste_psc", Text, nullable=True),
        Column("bydliste_cast_obce", Text, nullable=True),
        Column("bydliste_cislo_po", Text, nullable=True),
        Column("bydliste_cislo_or", Text, nullable=True),
        Column("bydliste_okres", Text, nullable=True),
        Column("bydliste_cislo_ev", Text, nullable=True),
        Column("bydliste_cislo_text", Text, nullable=True),
        Column("bydliste_doplnujici_text", Text, nullable=True),
    ),
    Table(
        "zahajeni_zruseni",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=False),
    ),
    Table(
        "euid",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("euid", Text, nullable=False),
    ),
    Table(
        "sicav",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=False),
    ),
    Table(
        "status_spolku",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=False),
    ),
    Table(
        "predmet_vedlejsi_cinnosti",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=True),
    ),
    Table(
        "omezeni_darcem",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("text", Text, nullable=False),
    ),
    Table(
        "znepristupneni_udaju",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("znepristupneno", Boolean, nullable=False),
    ),
    Table(
        "clen_sdruzeni_osoba",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("angazma_typ", Text, nullable=False),
        Column("text_osoba", Text, nullable=True),
        Column("text_zruseni", Text, nullable=True),
        Column("osoba_nazev", Text, nullable=True),
        Column("osoba_reg_cislo", Text, nullable=True),
        Column("osoba_ico", Integer, nullable=True),
        Column("osoba_euid", Text, nullable=True),
        Column("osoba_jmeno", Text, nullable=True),
        Column("osoba_prijmeni", Text, nullable=True),
        Column("osoba_datum_narozeni", Date, nullable=True),
        Column("adresa_stat_nazev", Text, nullable=False),
        Column("adresa_obec", Text, nullable=True),
        Column("adresa_ulice", Text, nullable=True),
        Column("adresa_psc", Text, nullable=True),
        Column("adresa_cast_obce", Text, nullable=True),
        Column("adresa_cislo_po", Integer, nullable=True),
        Column("adresa_cislo_or", Integer, nullable=True),
        Column("adresa_okres", Text, nullable=True),
        Column("adresa_adresa_text", Text, nullable=True),
    ),
    Table(
        "odstepny_zavod_vedouci",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("spravce", Boolean, nullable=True),
        Column("text", Text, nullable=True),
        Column("osoba_jmeno", Text, nullable=True),
        Column("osoba_prijmeni", Text, nullable=False),
        Column("osoba_datum_narozeni", Date, nullable=True),
        Column("osoba_titul_pred", Text, nullable=True),
        Column("osoba_titul_za", Text, nullable=True),
        Column("adresa_stat_nazev", Text, nullable=True),
        Column("adresa_ulice", Text, nullable=True),
        Column("adresa_psc", Text, nullable=True),
        Column("adresa_obec", Text, nullable=True),
        Column("adresa_cast_obce", Text, nullable=True),
        Column("adresa_cislo_po", Integer, nullable=True),
        Column("adresa_cislo_or", Integer, nullable=True),
        Column("adresa_okres", Text, nullable=True),
    ),
    Table(
        "nesrovnalost",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        # TODO: tyhle dve jsou ve skutecnosti datum, ale spatne uvedeny
        Column("zahajeni_rizeni", Text, nullable=True),
        Column("ukonceni_rizeni", Text, nullable=True),
        Column("zpusob_vyrizeni", Text, nullable=True),
        Column("verejna", Boolean, nullable=False),
        Column("text_prvni_faze", Text, nullable=True),
        Column("text_druha_faze", Text, nullable=True),
    ),
    Table(
        "min_kmenove_jmeni",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("vklad_typ", Text, nullable=False),
        # nechtel se mi delat vlastni parser, prece jen tu muzou dat cokoliv
        # co mi to rozbilo: 199.004.000,- Kč; 159.203.000,- Kč; 5,5 miliardy Kč
        Column("vklad", Text, nullable=False),
    ),
    Table(
        "evidence",
        meta,
        Column("ico", ForeignKey("subjekty.ico"), nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("evidence", Text, nullable=False),
    ),
    Table(
        "zakladatel_sf",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("udelen_souhlas", Boolean, nullable=False),
        Column("osoba_ico", Integer, nullable=True),
        Column("osoba_jmeno", Text, nullable=True),
        Column("osoba_prijmeni", Text, nullable=True),
        Column("osoba_datum_narozeni", Date, nullable=True),
        Column("osoba_titul_pred", Text, nullable=True),
        Column("osoba_titul_za", Text, nullable=True),
        Column("adresa_stat_nazev", Text, nullable=True),
        Column("adresa_obec", Text, nullable=True),
        Column("adresa_cast_obce", Text, nullable=True),
        Column("adresa_ulice", Text, nullable=True),
        Column("adresa_cislo_po", Text, nullable=True),
        Column("adresa_cislo_or", Text, nullable=True),
        Column("adresa_psc", Text, nullable=True),
        Column("adresa_okres", Text, nullable=True),
        Column("adresa_cislo_ev", Text, nullable=True),
        Column("adresa_text", Text, nullable=True),
        Column("bydliste_stat_nazev", Text, nullable=True),
        Column("bydliste_obec", Text, nullable=True),
        Column("bydliste_cast_obce", Text, nullable=True),
        Column("bydliste_cislo_po", Text, nullable=True),
        Column("bydliste_cislo_or", Text, nullable=True),
        Column("bydliste_psc", Text, nullable=True),
        Column("bydliste_ulice", Text, nullable=True),
    ),
    Table(
        "ucel_fondu",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("ucel", Text, nullable=False),
    ),
    Table(
        "vyzva_pro_veritele",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("ucel", Text, nullable=True),
        # TODO: maj tam bordel, proto text
        Column("datum_zverejneni", Text, nullable=False),
        Column("zverejneni", Text, nullable=False),
    ),
    Table(
        "obmysleny_zpusob",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("zpusob", Text, nullable=False),
    ),
    Table(
        "protektor",
        meta,
        Column("ico", Integer, nullable=False),
        Column("datum_zapis", Date, nullable=False),
        Column("datum_vymaz", Date, nullable=True),
        Column("udelen_souhlas", Boolean, nullable=False),
        Column("osoba_ico", Integer, nullable=True),
        Column("osoba_jmeno", Text, nullable=True),
        Column("osoba_prijmeni", Text, nullable=True),
        Column("osoba_datum_narozeni", Date, nullable=True),
        Column("osoba_titul_pred", Text, nullable=True),
        Column("osoba_titul_za", Text, nullable=True),
        Column("adresa_stat_nazev", Text, nullable=True),
        Column("adresa_obec", Text, nullable=True),
        Column("adresa_cast_obce", Text, nullable=True),
        Column("adresa_ulice", Text, nullable=True),
        Column("adresa_cislo_po", Text, nullable=True),
        Column("adresa_cislo_or", Text, nullable=True),
        Column("adresa_psc", Text, nullable=True),
        Column("adresa_okres", Text, nullable=True),
        Column("adresa_cislo_ev", Text, nullable=True),
        Column("adresa_text", Text, nullable=True),
    ),
]


if __name__ == "__main__":
    from sqlalchemy.dialects import postgresql
    from sqlalchemy.schema import CreateTable

    for table in schema:
        print(f"-- {table.name} as created in Postgres")

        print(CreateTable(table).compile(dialect=postgresql.dialect()))
