<?php

namespace App\Http\Controllers;

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

class NewArrivalController extends Controller
{
    public function __construct(ResponseRepository $response) {
        $this->response = $response;
        $this->ruleOne = [
            'arrival_title' => 'required',
        ];
        $this->ruletwo = [
            'collection_title' => 'required',
        ];
        $this->ruleThree = [
            'destination_title' => 'required',
            'destination_description' => 'required',

        ];
    }
    // get All data Function 
    public function getHomeNewArrival(){
        return $this->response->jsonResponse(false, "New Arrival Content Fetched Successfully", NewArrival::all(), 550);
    }
// update data function
    public function updateHomeNewArrivalSection(Request $request) {
        $validate = $this->response->validate($request->all(), $this->ruleOne);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('New Arrival Content', 'update'), NewArrival::first()->update($request->all()), 551);
        } else {
            return $this->response->jsonResponse(true, 'Content Update Failed', $validate, 552);
        }
    }
    // update data function
    public function updateHomeCollectionSection(Request $request) {
        $validate = $this->response->validate($request->all(), $this->ruletwo);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Collection Content', 'update'), NewArrival::first()->update($request->all()), 551);
        } else {
            return $this->response->jsonResponse(true, 'Content Update Failed', $validate, 552);
        }
    }
    // update data function
    public function updateHomeDestinationSection(Request $request) {
        $validate = $this->response->validate($request->all(), $this->ruleThree);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Destination Content', 'update'), NewArrival::first()->update($request->all()), 551);
        } else {
            return $this->response->jsonResponse(true, 'Content Update Failed', $validate, 552);
        }
    }
}
