<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
use App\Http\Controllers\Api\SendEmailController;
use Illuminate\Support\Facades\Http;
class TaskController extends Controller
{
    function GetNotUpdatedLeadDetails()
    {
        $payload = [
            'P_OPERATION_NAME' => 'VIEW_LIST_LEAD_MANAGEMENT',
            'P_ITEM' => 'NOT_UPDATED_LEAD',
            'P_USER_SYS_ID' => NULL,
        ];
        $response = DB::select("call USP_GET_LIST_LEAD_MANAGEMENT(:P_OPERATION_NAME, :P_ITEM, :P_USER_SYS_ID,  @ERRNO,@ERRMSG)", $payload);
        if(!empty($response)) {
            $response_decoded = json_decode($response[0]->JSON_VALUE, true);
            if($response_decoded['status'] == 'true'){
                $emailController = new SendEmailController();
                $LeadData = $response_decoded['response'];
                $emailController->sendEmailOfLeadNoUpdatedLastThreeDays($LeadData);
            }
        }
        else {
            $response_data = [ 'status' => 'false', 'response' => 'Opps!! something went wrong',];
            return $response_data;
        }
    }

    function GetNotUpdatedAllLeadDetails()
    {
        $payload = [
            'P_OPERATION_NAME' => 'VIEW_LIST_LEAD_MANAGEMENT',
            'P_ITEM' => 'NOT_UPDATED_LEAD',
            'P_USER_SYS_ID' => NULL,
        ];
        $response = DB::select("call USP_GET_LIST_LEAD_MANAGEMENT(:P_OPERATION_NAME, :P_ITEM, :P_USER_SYS_ID,  @ERRNO,@ERRMSG)", $payload);
        if(!empty($response)) {
            $response_decoded = json_decode($response[0]->JSON_VALUE, true);
            return $response_decoded;
        }
        else {
            $response_data = [ 'status' => 'false', 'response' => 'Opps!! something went wrong',];
            return $response_data;
        }
    }
}
