#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""class definition"""

import logging
from datetime import datetime
from pathlib import Path
from time import time

import openpyxl as ox
import xlwings as xw


# %% === App_Data
class App_Data:  # noqa: N801
    """APP-Data beinhaltet folgende Daten

    Note: Definitionen aus Excel übernehmen
    """

    # Logger Infos
    # ref: https://www.python-lernen.de/python-modul-datetime.htm
    strftime_format = '%y.%m.%d %H:%M:%S:%f'

    # Datei Infos
    strName: str = 'eSaver_Ausw_Erspar_v1.02.3'
    strPath_cwd = 'src'
    strPath_parent = 'eSaver_Ausw_Erspar_Py_v1.02.3.5_py31404'
    strPath_type_cwd = "<class 'pathlib._local.WindowsPath'>"  # "<class 'pathlib.PosixPath'>"  // Linux Rasp_pi
    strXlsm_FileNameMain: str = 'eSaver_Export_VIDA_Ausw_Erspar_SVB.xlsm'
    strInit_SheetName = 'Export-VIDA Main'
    strXlsm_FileNameDest: str = 'PJJ0X0XX_Name1-Name2 Ersparnis 2025_01-12 - Stundenbasiert.xlsx'
    strTimeFtime: str = ''
    strCurPath: str = ''
    xTableFound: int = 0

    wb_xw = xw.Book
    ws0 = wb_xw.activate
    listSheets_xw = ''

    wb = ox.Workbook
    ws = wb.active
    listSheets = ''

    # Datei Infos
    strPath_Export_Files = r'd:\P_20JJ\PJJ01xxx_Name-Name2\6 Mess-Janitza\VIDA - PLL0X0XX Ermittlung Ersparnis'

    strPath_Import_Files = r'd:\P_20JJ\PJJ01xxx_Name-Name2\6 Mess-Janitza\VIDA - PLL0X0XX Ermittlung Ersparnis'
    intExcelInitValue = 2

    list_Postfix = (
        '_01_Jan',
        '_02_Feb',
        '_03_Mrz',
        '_04_Apr',
        '_05_Mai',
        '_06_Jun',
        '_07_Jul',
        '_08_Aug',
        '_09_Sep',
        '_10_Okt',
        '_11_Nov',
        '_12_Dez',
    )

    tupl_strExportFile = (
        'PJJ0X0XX Export_VIDA-Data_2025_0101_2025_0201_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_0201_2025_0301_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_0301_2025_0401_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_0401_2025_0501_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_0501_2025_0601_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_0601_2025_0701_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_0701_2025_0801_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_0801_2025_0901_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_0901_2025_1001_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_1001_2025_1101_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_1101_2025_1201_GM.csv',
        'PJJ0X0XX Export_VIDA-Data_2025_1201_2026_0101_GM.csv',
    )

    tupl_strImportFile = (
        'PJJ0X0XX Export_VIDA-Data_2025_0101_2025_0201_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_0201_2025_0301_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_0301_2025_0401_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_0401_2025_0501_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_0501_2025_0601_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_0601_2025_0701_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_0701_2025_0801_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_0801_2025_0901_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_0901_2025_1001_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_1001_2025_1101_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_1101_2025_1201_Imp.xlsx',
        'PJJ0X0XX Export_VIDA-Data_2025_1201_2026_0101_Imp.xlsx',
    )


pass


# App_Data End

# print(help(App_Data))


"""
Ab hier beginnt das Test Programm
"""


# * =============================================
# %% === logger_Settings
def logger_Settings():
    """Logger Settings

    Initialisierung der Bezeichnung-Namen (EN)
    """
    logging.debug('debug Beschreibung Test der Meldungen')
    logging.info('info')
    logging.warning('warning')
    logging.error('error')
    logging.critical('critical')
    logging.info('info ========================================')
    logging.info('_PRG')

    return


# %% === logger_On
def logger_On(parent: Path, loggerFileName: str):
    """Einschalten des Loggers open Logger-file"""
    cwd = Path.cwd()
    parent = cwd.parent

    try:
        logging.getLogger().removeHandler(logging.getLogger().handlers[0])
        logging.getLogger().removeHandler(logging.getLogger().handlers[0])
    except:  # noqa: E722
        pass

    strTimeFtime = datetime.now().strftime('%y%m%d_%H%M%S')

    logFileName = f'{loggerFileName}{strTimeFtime}.log'

    strFileLog = parent / logFileName
    print(f'>>> Log_FileName: {strFileLog}')
    logging.basicConfig(
        filename=strFileLog,
        filemode='w',  # default = 'a'
        format='%(asctime)s %(name)15s - %(levelname)8s: - %(message)s',
        datefmt='%d.%m.%y %H:%M:%S',
        level=logging.INFO,
    )
    return


# %% === logger_Off
def logger_Off():
    """Ausschalten des Loggers close Logger-file"""
    logging.shutdown()

    return


# ? =============================================
# %% === main_testen_App_Data
def main_testen_App_Data():
    logging.info('main_testen main_func')

    return


# %% === main
def main():
    """___

    ___
    """
    tStart = time()  # todo: Zeitmessung

    # ## === Variables Global anlegen
    app_data = App_Data()

    # ## === Path-Variablen holen ===
    cwd = Path.cwd()
    parent = cwd.parent

    # ========== logger aktivieren ==========
    # ?: Hier sollte der Dateiname aus der App_Data.xx gelesen werden.
    logger_On(parent, 'x_eSaver_Data_App_Log_')
    logger_Settings()

    strTimeFtime = datetime.now().strftime(app_data.strftime_format)
    logging.info('main_testen started                                           / Start {strTimeFtime}')

    pass  # ## ==========

    main_testen_App_Data()

    pass  # ## ==========

    tEnde = time()  # todo: Zeitmessung
    tDauer = tEnde - tStart
    logging.info(f'main_testen stopped                                          / tDauer {tDauer}')

    logger_Off()

    return


# %% === Start __main__
if __name__ == '__main__':
    """Einsprung Start der Anlage

    """
    # ## === Variables Global anlegen
    pass

    main()

    pass  # ## ==========


# %% === EOF
# EOF                   // End of File
