<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models;
// use Illuminate\Contracts\Mail\Mailer;



class UtilityController extends Controller
{

    public function EmailTest(Mailer $mailer)
    {

        $emails = ['kwesi@click-mobile.com', 'kwesi_banson@hotmail.com'];

        $data = [
            'client' => 'test client',
            'created_by' => 'Kwesi',
            'services' => 'test services',
            'notes_body' => 'test notes'
        ];
        $mailer->send('emails.new-notes', $data, function ($message) use ($data, $emails) {
            $message->from('erp@click-mobile.com', 'Click Mobile ERP');
            $message->to($emails)->subject('New Notes');
        });
    }
    public function maptest(){

        return view('utility.map');
    }

    public function showPage(){

        return view('utility.arraylogic');
    }
    public function ntfyTest(){
        $this->sendNtfy('In the ERP');
    }
    public function paperlessTest(){
      $file_path = "documents/oasl.pdf";
      $tags_arr = [1,2];
      $created_at = date('Y-m-d H:i:s');
      $document_type = 1;
      $title = "OASL has entered the chat";
      $top = $this->sendToPaperless($file_path, $tags_arr, $created_at, $document_type, $title);
      dd($top);
    }
    function getPaperlessAttributes($name){
      $retval = $this->getToPaperlessParamValues($name);
      // dd($retval['results']);
      $tip = json_decode($retval);
      dd($tip);
      foreach ($tip->results as $value) {
        dd($value);
      }
      dd($tip->results);

    }
    function insertOnboardingProgress(){
        $all_clients = Models\Client::get();
        $count_cl = 0;
        foreach ($all_clients as $row) {
            $get_stage_subs_items = Models\ClientOnboardingSubItem::get();
            foreach ($get_stage_subs_items as $value) {
                $stage_id = ['stage_id' => $value->stage_id, 'client_id' => $row->id, 'name' => $value->name ];
                $progress_arr = [
                    'status' => 'PENDING'
                ];
                $clients_onboarding_progress = Models\ClientOnboardingProgress::updateOrCreate($stage_id, $progress_arr);
            }
            $count_cl++;
        }
        dump($count_cl);
    }
    function massOnboardingProgress($client_id){
        //todo : update
        /*
        -- client_onboarding_sub_items -- this holds all sub items
        -- client_onboarding_progress -- update to completed
        -- in the clients table
            -- onboarding_progress_stage == update to complete,
            -- progress_indicator to complete,
            -- progress_indicator_score to 100
        */
        $get_stage_subs_items = Models\ClientOnboardingSubItem::get();
        foreach ($get_stage_subs_items as $value) {
            $progress_arr = [
                'stage_id' => $value->stage_id,
                'client_id' => $client_id,
                'name' => $value->name,
                'status' => 'COMPLETE'
            ];
            $clients_onboarding_progress = Models\ClientOnboardingProgress::create($progress_arr);
        }
        $all_clients = Models\Client::get();
        $count_cl = 0;
        foreach ($all_clients as $row) {
            $get_stage_subs_items = Models\ClientOnboardingSubItem::get();
            foreach ($get_stage_subs_items as $value) {
                $stage_id = ['stage_id' => $value->stage_id, 'client_id' => $row->id, 'name' => $value->name ];
                $progress_arr = [
                    'status' => 'PENDING'
                ];
                $clients_onboarding_progress = Models\ClientOnboardingProgress::updateOrCreate($stage_id, $progress_arr);
            }
            $count_cl++;
        }
        dump($count_cl);
    }
}
// https://www.tokyvideo.com/video/sheena-the-queen-of-the-jungle-1984-movie-with-tanya-roberts-ted-wass-donovan-scott
