<?php

namespace App\Http\Controllers;
use App\Models\FooterBlock;
use App\Models\ConsultUs;
use Illuminate\Http\Request;
use App\Repositories\ResponseRepository;

class FooterBlockController extends Controller
{
    public function __construct(ResponseRepository $response) {
        $this->response = $response;
        $this->storeRules = [
            'whatsapp_link' => 'required',
            'phone_number' => 'required',
            'email' => 'required',
            'insta_link' => 'required',
            'facebook_link' => 'required',
        ];
    }

    public function getFooterBlock() {
        $data['consultUs'] = ConsultUs::where('active_status', 1)->orderBy('id', 'desc')->get();
        $data['footerBlock'] = FooterBlock::all();
        return $this->response->jsonResponse(false, "Media Link Details Fetched Successfully", $data, 200);
    }

    public function updateFooterBlock(Request $request) {
        $validate = $this->response->validate($request->all(), $this->storeRules);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Media Link Details', 'update'), FooterBlock::first()->update($request->all()), 200);
        } else {
            return $this->response->jsonResponse(true, 'Media Link Details Update Failed', $validate, 201);
        }
    }
}
