<?php

namespace App\Http\Controllers;

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

class HeaderImageController extends Controller
{
    public function __construct(ResponseRepository $response) {
        $this->response = $response;
        $this->storeRules = [
            'title_one' => 'required',
            'title_one_two' => 'required',
            'title_one_three' => 'required',
            'title_two' => 'required',
            'title_two_content' => 'required',
        ];
    }

    public function getHeaderImage() {
        return $this->response->jsonResponse(false, "Home Page Content Fetched Successfully", HeaderImage::all(), 200);
    }

    public function updateHeaderImage(Request $request) {
        $validate = $this->response->validate($request->all(), $this->storeRules);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Home Page', 'update'), HeaderImage::first()->update($request->all()), 200);
        } else {
            return $this->response->jsonResponse(true, 'Home Page Update Failed', $validate, 201);
        }
    }
}
