<?php

namespace App\Http\Controllers\Admin\APIs\Customer_API;

use App\Http\Controllers\Controller;
use App\Services\APIs\CustomerAPIs\CMSApiServices;
use Illuminate\Http\Request;
use Exception;
use Illuminate\Support\Facades\Log;

class CMSApiController extends Controller
{
    protected $CMSApiServices;

    public function __construct(CMSApiServices $CMSApiServices)
    {
        $this->CMSApiServices = $CMSApiServices;
    }

 /**
     * Created By : sayli Raut
     * Created at : 23 May 2024
     * Use : To get faq detail.
     */
    public function getfaq()
    {
        try {
            $token = readHeaderToken();

            if ($token) {
                $customerIamId = $token['sub'];
                $response = $this->CMSApiServices->getfaq();
                return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $response, 200);
            } else {
                return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
            }
        } catch (Exception $e) {
            Log::error('FAQ get data controller function failed: ' . $e->getMessage());
            return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
        }
    }
  /**
     * Created By : sayli Raut
     * Created at : 23 May 2024
     * Use : To get about us detail.
     */
    public function getAboutUs()
    {
        try {
            $token = readHeaderToken();
            if ($token) {
                $customerIamId = $token['sub'];
                $response = $this->CMSApiServices->getAboutUs();
                return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $response, 200);
            } else {
                return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
            }
        } catch (\Exception $e) {
            Log::error('Abot us get data controller function failed: ' . $e->getMessage());
            return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
        }
    }

    /**
     * Created By : sayli Raut
     * Created at : 24 May 2024
     * Use : To get privacy policy detail.
     */
    public function getPrivacyPolicy()
    {
        try {
            $token = readHeaderToken();
            if ($token) {
                $customerIamId = $token['sub'];
                $response = $this->CMSApiServices->getPrivacyPolicy();
                return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $response, 200);
            } else {
                return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
            }
        } catch (\Exception $e) {
            Log::error('Privacy policy get data controller function failed: ' . $e->getMessage());
            return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
        }
    }

    /**
     * Created By : sayli Raut
     * Created at : 24 May 2024
     * Use : To get News and Articles detail.
     */
    public function getNewsArticles()
    {
        try {
            $token = readHeaderToken();
            if ($token) {
                $customerIamId = $token['sub'];
                $response = $this->CMSApiServices->getNewsArticles();
                return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $response, 200);
            } else {
                return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
            }
        } catch (\Exception $e) {
            Log::error('News and articles data controller function failed: ' . $e->getMessage());
            return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
        }
    }


     /**
     * Created By : sayli Raut
     * Created at : 24 May 2024
     * Use : To get priivacy policy detail.
     */
    public function getTermsConditon()
    {
        try {
            $token = readHeaderToken();
            if ($token) {
                $customerIamId = $token['sub'];
                $response = $this->CMSApiServices->getTermsConditon();
                return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $response, 200);
            } else {
                return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
            }
        } catch (\Exception $e) {
            Log::error('FAW get data controller function failed: ' . $e->getMessage());
            return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
        }
    }

}
