<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\YoutubeModel;
use Session;
class YoutubeController extends Controller
{
    function youtubelinks(){
        $result = $this->getNoteName();
        return view('masters/youtubelinks',['data'=>$result]);
    }
    function viewYoutubeLinkList(Request $req){
        $result = YoutubeModel::all();
        return view('masters/viewyoutubelinkslist',['data'=>$result]);
    }

    function getNoteName(){
        $result = YoutubeModel::select('Name','Details')->distinct()->get();
        return $result;
    }
    function saveYoutubeLink(Request $req){
        if($req->action == 'Save'){
            $Package = new YoutubeModel;
        }
        else{
            $Package = YoutubeModel::find($req->id);
        }
        $Package->Name = $req->Name; 
        $Package->Details = $req->Details;
        $Package->Status = $req->Status;
        
        $Package->save();
        return 1;
    }

    function editYoutubeLink(Request $req){
        $data = YoutubeModel::find($req->id);
        return json_encode($data);
    }

    function deleteYoutubeLink(Request $req){
        $data=YoutubeModel::find($req->id)->delete();
        return 1;
    }

    function sendYoutubeLink(Request $req){
        $youtubelink = $req->YoutubeLink;
        //$youtubelink = "";
      $msg = "Please Watch Video. Click on link <br>".$youtubelink;
      $msg.= " Vyawahare Netralaya Amravati. For Any Qurey please Call 9370109617,9552731024";
      $sms_text = strip_tags($msg);
      $api_url = "https://smswaapi.in/api/send?number=91".$req->WhatsappNo."&type=text&message=".$sms_text."&instance_id=64B0F93ED3A13&access_token=649d339dbf9f2";
      $response = file_get_contents( $api_url);
        return 1;
    }

    function SendYoutubeLinks(){
        $result = $this->getNoteName();
        return view('youtubelinks/send-youtube-links',['brochurelist'=>$result]);
    }
    
}
