import inspect
import os
import sqlite3


def dict_factory(cursor, row):
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d


class ITezgah(): pass


class ITezgahlar():
    def __init__(self):
        super(ITezgahlar, self).__init__()
        # -->
        self.__kokDizin = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()) + "\\..\\..\\.."))
        self.__conn = sqlite3.connect(os.path.join(self.__kokDizin,'Prg','Tezgah Profilleri','tezgahlar.fikoDB'))
        self.__conn.row_factory = dict_factory
        self.__c = self.__conn.cursor()

    def item(self, val):
        self.__c.execute("""SELECT * FROM tezgahlar WHERE ismi=:isim ORDER BY siraNo""", {"isim": val})
        return ITezgah(self.__c.fetchone())

    @property
    def sayisi(self) -> int:
        self.__c.execute("""SELECT COUNT(ismi) AS Sayi FROM tezgahlar;""")
        return self.__c.fetchone()["Sayi"]

    @property
    def tezgahlarTumu(self) -> list:
        self.__c.execute("""SELECT * FROM tezgahlar ORDER BY siraNo""")
        return [ITezgah.ITezgah(row) for row in self.__c]

    def __call__(self) -> list:
        return [self.tezgahlarTumu]

    def __str__(self) -> str:
        return repr([x.ismi for x in self.tezgahlarTumu])

    def __getitem__(self, item) -> ITezgah:
        return self.tezgahlarTumu[item]

import sys
sys.path.append(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()) + "\\..\\..\\..")))

import Projeler.QTBilesenleri.FikoBehemilPost.ITezgah