<?php

namespace App\Http\Controllers;

namespace App\Http\Controllers;
use App\Models\SeoPages;
use App\Repositories\ResponseRepository;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;

class SeoPagesController extends Controller
{
    public function __construct(ResponseRepository $response) {
        $this->response = $response;
        $this->rule = [
            'home_seo_title' => 'required' ,
            'home_seo_description' => 'required' ,
        ];
        $this->ruleTwo = [
            'about_seo_title' => 'required' ,
            'about_seo_description' => 'required' ,
        ];
        $this->ruleThree = [
            'contact_seo_title' => 'required' ,
            'contact_seo_description' => 'required' ,
        ];
        $this->ruleFour = [
            'gallery_seo_title' => 'required' ,
            'gallery_seo_description' => 'required' ,
        ];
    }
    // data get function
    public function getAllSeoPagesData() {
        return $this->response->jsonResponse(false, "Seo Pages Fetched Successfully", SeoPages::all(), 550);
    }
    // Data Update Function
    public function updateHomeSeoPagesData(Request $request) {
        $validate = $this->response->validate($request->all(), $this->rule);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Content', 'update'), SeoPages::first()->update($request->all()), 551);
        } else {
            return $this->response->jsonResponse(true, 'Content Update Failed', $validate, 552);
        }
    }
        // Data Update Function
    public function updateAboutSeoPagesData(Request $request) {
        $validate = $this->response->validate($request->all(), $this->ruleTwo);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Content', 'update'), SeoPages::first()->update($request->all()), 551);
        } else {
            return $this->response->jsonResponse(true, 'Content Update Failed', $validate, 552);
        }
    }
    // Data Update Function
    public function updateContactSeoPagesData(Request $request) {
        $validate = $this->response->validate($request->all(), $this->ruleThree);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Content', 'update'), SeoPages::first()->update($request->all()), 551);
        } else {
            return $this->response->jsonResponse(true, 'Content Update Failed', $validate, 552);
        }
    }
    // Data Update Function
    public function updateGalleryPagesSeoData(Request $request) {
        $validate = $this->response->validate($request->all(), $this->ruleFour);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Content', 'update'), SeoPages::first()->update($request->all()), 551);
        } else {
            return $this->response->jsonResponse(true, 'Content Update Failed', $validate, 552);
        }
    }
    
}
