import os
import datetime
from flask import Blueprint, request, jsonify
from config import LABEL_FOLDER, IMAGE_FOLDER
delete_bp = Blueprint('delete', __name__)

@delete_bp.route('/delete/<image_name>', methods=['DELETE'])
def delete_image(image_name):

    today_str = datetime.datetime.now().strftime("%Y-%m-%d")

    image_path = os.path.join(IMAGE_FOLDER,today_str, image_name)
    
    label_path = os.path.join(LABEL_FOLDER,today_str, f"{image_name}.txt")

    if os.path.exists(image_path):
        os.remove(image_path)
    else:
        return jsonify({"error": "Image not found"}), 404

    if os.path.exists(label_path):
        os.remove(label_path)

    return jsonify({"message": "Image and label deleted successfully", "status": "true"})