<?php

namespace App\Http\Controllers\Api;

use App\Models\JobOrder;
use App\Models\OneTimePin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Http;

class SMSController extends Controller
{

    public function sendOTP (Request $request)
    {

        $jobOrder = JobOrder::where('order_no', $request->order_no)->first();

        $otp = OneTimePin::create([
            'otp' => rand(100000, 999999),
            'mobile_no' => $jobOrder->mobile_no,
            'email' => $jobOrder->email,
        ]);

        return $otp->otp;

        $response = Http::post('https://api.itexmo.com/api/broadcast', [
            'Email' => 'cloud.rweb@gmail.com',
            'Password' => 'RW3bS0luti0nsC0rp',
            'Recipients' => [$jobOrder->mobile_no],
            'Message' => 'Hello',
            'ApiCode' => 'PR-RWEBS392247_7EMET',
            'SenderId' => 'RWeb',
        ]);

        return $response;
    }
}
