<?php

namespace App\Services\APIs\CustomerAPIs;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Models\IamPrincipal;
use App\Models\ManageContactus;
use Throwable;



class ContactUsApiServices
{


    public function addCustomerRestaurantContactForm($request)
    {
        try {
            DB::beginTransaction();
            //create user_data
            $user_data = IamPrincipal::where('id', $request['iam_principal_id'])->first();
            if ($user_data) {
                // Create a new instance of ManageContactus model
                $contact = new ManageContactus();
                $contact->principal_xid = $user_data->id;
                $contact->name = $request->name;
                $contact->email = $request->email;
                $contact->message = $request->message;
                // Save the contact data
                $contact->save();

                DB::commit();

                //response data
                Log::info('Contact form data Created successfully');
                return jsonResponseWithSuccessMessageApi(__('success.save_data'), [], 201);
            } else {
                Log::error('Contact not found in addVendorContactForm.');
                return jsonResponseWithErrorMessageApi(__('auth.validation_failed'), 403);
            }
        } catch (Throwable $ex) {
            DB::rollBack();
            Log::error('Contact API failed : ' . $ex->getMessage());
            return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
        }
    }
}
