from flask import Flask, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS
from dotenv import load_dotenv
import os
from flask_bcrypt import Bcrypt
import redis
from flask_session import Session

app = Flask(__name__)
CORS(app, supports_credentials=True)
load_dotenv()
bcrypt = Bcrypt(app)


app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///mydatabase.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SQLALCHEMY_ECHO"] = True
app.config["SECRET_KEY"] = os.environ["SECRET_KEY"]
app.config["SESSION_TYPE"] = 'redis'
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_USE_SIGNER"] = True
app.config["SESSION_REDIS"] = redis.from_url("redis://192.168.50.107:6379")
# upload directory
app.config["UPLOAD_DIRECTORY"] = 'uploads/'
# app.config["UPLOAD_DIRECTORY"] = '../frontend/public/batch1'
# app.config["REDIS_PASSWORD"] = os.environ["REDIS_PASSWORD"]

# File value limit
app.config["MAX_CONTENT_LENGTH"] = 16 * 1024 * 1024 # 16MB

# List of allowed file extensions
app.config['ALLOWED_EXTENSIONS'] = ['.jpg', '.jpeg', '.png', '.gif']

db = SQLAlchemy(app)

server_session = Session(app)
# 22:16