<?php
namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Models\QueryManagementModel;
use Illuminate\Support\Facades\Log;

class UpdateStatusController extends Controller
{
   public function updateStatus(Request $request, $queryId)
   {
      try {
           $IDD = $queryId;
         $query = QueryManagementModel::where('ID', $IDD); // Use findOrFail for error handling
         $query->update(['status' => 'A']); // Update status to 'A'
         return response()->json(['success' => true, 'message' => 'Status updated to Active']);
      } catch (\Exception $e) {
         \Log::error("Error updating status: " . $e->getMessage()); // Log the error
         return response()->json(['success' => false, 'message' => 'Error updating status'], 500);
      }
   }
   public function closeStatus(Request $request, $closeStatusId)
   {
      try {
           $IDD2 = $closeStatusId;
         $query = QueryManagementModel::where('ID', $IDD2); // Use findOrFail for error handling
         $query->update(['status' => 'C']); // Update status to 'A'
         return response()->json(['success' => true, 'message' => 'Status updated to Active']);
      } catch (\Exception $e) {
         \Log::error("Error updating status: " . $e->getMessage()); // Log the error
         return response()->json(['success' => false, 'message' => 'Error updating status'], 500);
      }
   }
   
  public function deleteQuery($queryId){
        return response()->json(['success' => true]);
    //  try {
    //         // Find the query by ID
    //         $query = QueryManagementModel::findOrFail($queryId);
    //         echo $query

    //         // // Log the query before deletion
    //         // Log::info('Query to be deleted: ', ['query' => $query]);

    //         // // Delete the query
    //         // // $query->delete();

    //         // return response()->json(['success' => true, 'message' => 'Query deleted successfully.', 'query' => $query]);
            
    //         return redirect('/hello')
    //     } catch (\Exception $e) {
    //         Log::error('Error deleting query: ' . $e->getMessage());

    //         return response()->json(['success' => false, 'message' => 'Error deleting query'], 500);
    //     }
  }
   
}
