<?php
error_reporting(E_ALL);
ini_set('display_errors',1);

if(!isset($_GET['id']))
{
    http_response_code(500);
            echo json_encode(['error_text' => 'Something Went Wrong']);
            exit;
}
$id = $_GET['id'];

session_start();
require_once "../check_admin.php";
require_once '../database.php';

if(!isset($_SESSION['user_type']) || $_SESSION['user_type'] !='staff')
{
        http_response_code(403);
        echo json_encode(['error_text' => 'Authentication Error']);
        exit;
}

class deleteOrderItem extends database
{
    public function index($id)
    {
        return $this->update('order_item', ['deleted_at' => date('Y-m-d H:i:s')], ['id' => $id]);
    }
}

$obj = new deleteOrderItem();
$res = $obj->index($id);
if(!$res)
    {
        http_response_code(500);
        echo json_encode(['error_text' => 'Something Went Wrong']);
        exit;
    }
    
    http_response_code(200);
        echo json_encode(['message' => 'Item Deleted Successful']);
        exit;