<?php

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

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

class RulesControllerAPI extends Controller
{

    protected $RulesApiServices;

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

    /**
     * Created By : sayli Raut
     * Created at : 19 June 2024
     * Use : To get voucher rules and regulation.
     */
    public function getVoucherRules()
    {
        try {
            $token = readHeaderToken();
            if ($token) {
                $customerIamId = $token['sub'];
                $response = $this->RulesApiServices->getVoucherRules();
                return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $response, 200);
            } else {
                return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
            }
        } catch (\Exception $e) {
            Log::error('Voucher rules get data controller function failed: ' . $e->getMessage());
            return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
        }
    }
}
