<?php

namespace App\Http\Controllers;

use App\Models\Contactus;

use Illuminate\Http\Request;

class ContactUsController extends Controller
{
    public function submit(Request $request)
    {
        $request->validate([
             'c_name' => 'required',
             'c_phone' => 'required',
             'c_title' => 'required',
             'c_describe' => 'required'
        ]);
        // if (Auth::check()) {
        //     $user_id = Auth::user()->user_id;
        // }
        $data = Contactus::create([
            'c_name' => $request->c_name,
            'c_user_id' => 0,
            'c_phone' => $request->c_phone,
            'c_title' => $request->c_title,
            'c_describe' => $request->c_describe
        ]);
        $id = $data->id;
        return response()->json([
            'status' => 'succeed',
            'message' => '',
            'id' => $id
            ]);
    }



    public function peygiri(Request $request)
    {
        $request->validate([
             'id' => 'required|exists:contactuses,id',
             'c_phone' => 'required|exists:contactuses,c_phone'
        ]);

        $status = 0;
        $data = Contactus::find($request->id);
        if ($data) {
            $status = 1;
        }
        return response()->json([
            'status' => 'succeed',
            'message' => '',
            'data' => $data,
            'status' => $status
            ]);
    }
}
