from datetime import datetime


apis_py = """from panther.app import API


@API.get()
async def hello_world():
    return {'detail': 'hello world'}

"""

models_py = """from panther.db import BaseModel

"""

serializers_py = """from pydantic import BaseModel

"""

app_urls_py = """from app.apis import hello_world

urls = {
    '': hello_world,
}

"""

configs_py = """\"""
Generated by Panther on %s
\"""

from pathlib import Path
from dotenv import dotenv_values


DEBUG = True 
BASE_DIR = Path(__name__).resolve().parent
env = dotenv_values(BASE_DIR / '.env')

DB_NAME = env['DB_NAME']
SECRET_KEY = env['SECRET_KEY']

Middlewares = [
    ('panther/middlewares/db.py', {'url': f'sqlite:///{BASE_DIR}/{DB_NAME}.db'}),
]

URLs = 'core/urls.py'
""" % datetime.now().date().isoformat()

middlewares_py = """from panther.middlewares import BaseMiddleware

"""

env = """
SECRET_KEY = 'THIS_IS_THE_SECRET_SECRET_KEY'

DB_NAME = '{DATABASE_NAME}'

"""

main_py = """import uvicorn
from panther import Panther

app = Panther(__name__)

if __name__ == '__main__':
    uvicorn.run('main:app')

"""

urls_py = """from app.urls import urls as app_urls

urls = {
    '': app_urls, 
}

"""

alembic_ini = """# A generic, single database configuration (Generated by panther).

[alembic]
script_location = alembic
prepend_sys_path = .
version_path_separator = os  
sqlalchemy.url = {SQLALCHEMY_URL}

[post_write_hooks]

[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
"""

Template = {
    'app': {
        'apis.py': apis_py,
        'models.py': models_py,
        'serializer.py': serializers_py,
        'urls.py': app_urls_py,
    },
    'core': {
        'configs.py': configs_py,
        'middlewares.py': middlewares_py,
        'urls.py': urls_py,
    },
    '.env': env,
    'alembic.ini': alembic_ini,
    'main.py': main_py,
}
