from flask import Flask, jsonify, request
from flask_cors import CORS
from process_image import download_image,process_Parkimage,process_image
from send_notification import send_mail
from config import Config
from database import db

app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)

@app.route('/filereceived', methods=['POST'])
def filereceived():
    data = request.get_json()
    if data.get('filepath'):
        file_path = data["filepath"].replace('/mnt/spaces/', '')
        splited_path_data = file_path.split('/')
        saved_file_path = download_image(file_path)
        model_result = process_image(saved_file_path)
        if model_result:
            send_mail({"partnerId":splited_path_data[0]})
        splited_raw_data = file_path.split('/')
        partnersid=splited_raw_data[0]
        locationame=splited_raw_data[1]
        saved_file_path1 = download_image(file_path)
        model_result1 = process_Parkimage(saved_file_path1,partnersid,locationame,file_path)

    return jsonify({'success': True,'result': model_result})

# @app.route('/filereceivedpark', methods=['POST'])
# def filereceivedpark():
#     data = request.get_json()
#     if data.get('filepath'):
#         file_path = data["filepath"].replace('/mnt/spaces/', '')
#         splited_path_data = file_path.split('/')
#         saved_file_path = download_image(file_path)
#         model_result = process_Parkimage(saved_file_path)
#         if model_result:
#             send_mail({"partnerId":splited_path_data[0]})

#     return jsonify({'success': True,'result': model_result})


if __name__ == '__main__':
    app.run(debug=False,port=8000,host="0.0.0.0")