<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use App\Models\ActionPerameter;
use App\Models\AppSetting;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
use function GuzzleHttp\Promise\all;

class AppSettingController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return JsonResponse|array
     */
    public function index()
    {
        $data = AppSetting::first();

        if ($data) {
            return ['result' => 1, 'message' => 'Resources data found.', 'data' => new JsonResponse($data)];
        }else{
            return response()->json(['result' => 0, 'message' => 'No data found.']);
        }
    }

    /**
     * @param Request $request
     * @return JsonResponse|array
     */
    public function store(Request $request)
    {
        $status = null;
        $keys = $request->except('_token');
        foreach ($keys as $key => $value)
        {
            $status = AppSetting::apiSet($key, $value);
        }

        if ($status) {
            return ['result' => 1, 'message' => 'Record successfully updated.', 'data' => new JsonResponse($status)];
        }else{
            return response()->json(['result' => 0, 'message' => 'Record not updated, Somethings wrong.']);
        }
    }
}
