<?php

namespace App\Http\Controllers;

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

class ContactUsController extends Controller
{
    public function __construct(ResponseRepository $response) {
        $this->response = $response;
        $this->storeRules = [
            'customer_name' => 'required',
            'customer_no' => 'required',
            'comments' => 'required',
        ];
    }

    public function show($id) {
        return $this->response->jsonResponse(false, $this->response->message('Contact Us Details', 'show'), $this->findContactUs($id), 200);
    }

    public function findContactUs($id) {
        return ContactUs::find($id);
    }

    public function getContactUsDetails() {
        return $this->response->jsonResponse(false, $this->response->message('Contact Us Details', 'index'), ContactUs::orderBy('id', 'desc')->get(), 200);
    }

    public function contactUsCreate(Request $request) {
        // Log::info('request =='. $request);
        $validate = $this->response->validate($request->all(), $this->storeRules);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Contact Us Details', 'store'), ContactUs::create($request->all()), 200);
        } else {
            return $validate;
        }
    }
}
