<?php

namespace App\Http\Controllers;

use App\Models\Plan;
use App\Models\HomePage;
use App\Models\SiteDetail;
use App\Models\Category;
use App\Models\Breed;
use App\Models\Product;
use App\Models\CompanyDetail;
use App\Models\Testimonial;
use App\Models\Investment;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class HomePageController extends Controller
{
    public function home(){
        //\Artisan::call('storage:link');
        //\Artisan::call('config:cache');

        return view('welcome');
    }

    /**
     * This method routes to the expanded package details where payment can be made
     */
    public function package($plan_name)
    {
       // $ses_plan_name = session(['amount' => $plan_name]);

        # Get the selected package 
        $selected_plan = Plan::where('name', $plan_name)->first();
        
        $bank = CompanyDetail::where('title', 'bank')->first();
        
        $account_name = CompanyDetail::where('title', 'account_name')->first();
        
        $account_number = CompanyDetail::where('title', 'account_number')->first();

        # Instantiate the parent controller class
        $parent_controller = new ParentFrontendController();

        # Get the data to pass to view
        $data = $parent_controller->global_datas('expand_package');
        $data += [
           'plan' => $selected_plan,
           'bank' => $bank,
           'account_name' => $account_name,
           'account_number' => $account_number,
        ];

       return view('selected_plan', $data);
    }
    
    public function pop(){
        
        # Instantiate the parent controller class
        $parent_controller = new ParentFrontendController();

        # Get the data to pass to view
        $data = $parent_controller->global_datas('expand_package');

       return view('pop', $data);
        
    }


    /**
     * Show plans for users attempting to re-invest
     */
    public function reinvest_plans()
    {
        # Get all available plans
        $plans = Plan::all();
        # Instantiate the parent controller class
        $parent_controller = new ParentFrontendController();

        # Get the data to pass to view
        $data = $parent_controller->global_datas('home');
        $data += [
        'plans' => $plans,
        ];

    return view('investments', $data);
    }
    
    
    #User Add testimonial
    public function testify(){
        
     # Instantiate the parent controller class
     $parent_controller = new ParentFrontendController();

     # Get the data to pass to view
     $data = $parent_controller->global_datas('home');
     
     if(Auth::check()){
         $investment = Investment::where('user_id', auth()->user()->id)->whereIn('status', [2,3])->get();
     }else{
         $investment = null;
     }
     
     $data += [
        'investment' => $investment,
     ];
     
     
    return view('testify', $data);
       
    }
    
    
}
