<?php

namespace App\Http\Controllers;
use App\Models\FooterBlock;
use App\Models\AboutUs;
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 = [
            // 'web_site' => 'required',
            'phone_number' => 'required',
            'insta_link' => 'required',
            'facebook_link' => 'required',
            'whats_app' => 'required',
            'address' => 'required',
            'address_two' => 'required',
        ];
    }

    // public function getFooterBlock() {
    //     return $this->response->jsonResponse(false, "Social Link Details Fetched Successfully", FooterBlock::all(), 200);
    // }

    public function getFooterBlock() {
        $data['homepageTitle'] = AboutUs::select('social_title', 'id')->get();
        $data['footerBlock'] = FooterBlock::orderBy('id', 'desc')->get();
        return $this->response->jsonResponse(false,"Social Link Details Fetched Successfully", $data , 300);
    }

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