<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\WhyChoose;
use App\Repositories\ResponseRepository;
use Illuminate\Support\Facades\Log;

class WhyChooseController extends Controller
{
    public function __construct(ResponseRepository $response) {
        $this->response = $response;
        $this->storeRules = [
            'header' => 'required',
            'description' => 'required',
        ];
    }

    public function getWhyChoose() {
        return $this->response->jsonResponse(false, "Why Choose Content Fetched Successfully", WhyChoose::all(), 200);
     }

     public function updateWhyChoose(Request $request) {
         $validate = $this->response->validate($request->all(), $this->storeRules);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Why Choose Content', 'update'), WhyChoose::first()->update($request->all()), 200);
        } else {
            return $this->response->jsonResponse(true, 'Why Choose Content Update Failed', $validate , 201);
        }
    }
}
