<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\ManageReferralRule;
use Illuminate\Http\Request;


class ManageReferralController extends Controller
{
     /**
     * Created By : sayali parab
     * Created at : 22 July 2024
     * Use : To view Rules page.
     */
    public function index()
    {
        $referral_rule = ManageReferralRule::all()->toArray();
        return view('Admin.pages.manage_rule.manage_referral', compact('referral_rule'));
    }


      /**
     * Created By : sayali parab
     * Created at : 22 July 2024
     * Use : To edit Rules.
     */
    public function editReferral($id)
    {
        $referral_rule = ManageReferralRule::find($id);
        // dd($referral_rule);
        return view('Admin.pages.manage_rule.manage_referral_edit', compact('referral_rule'));
    }


    public function updateReferral(Request $request)
    {
        $validated = $request->validate([

            'how_it_works' => 'required',
            'rules' => 'required',
            'what_is_referral' => 'required',

        ]);

        $howItWorks = base64_decode($request->input('how_it_works'));
        $rules = base64_decode($request->input('rules'));
        $whatIsReferral = base64_decode($request->input('what_is_referral'));


        $update = ManageReferralRule::find($request->rule_id);
        $update->how_it_works= $howItWorks;
        $update->rules = $rules;
        $update->what_is_referral= $whatIsReferral;

        $update->save();
        return response()->json(['success' => true, 'status' => 200]);
    }




}
