<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\SettingsService;
use App\Services\RenderService;

class SettingsAPIController extends Controller
{
    protected $settings;
    protected $render;

    public function __construct(SettingsService $settingsService, RenderService $renderService)
    {
        $this->settings = $settingsService;
        $this->render   = $renderService;
    }

    public function publish(Request $request)
    {
        $result = $this->render->publishAll();
        return response()->json($result)->header('Content-Type', 'application/json');
    }

    public function sync(Request $request)
    {
        $body   = json_decode($request->getContent());
        $result = $this->settings->sync($body);
        return response()->json($result)->header('Content-Type', 'application/json');
    }

    public function navSync(Request $request)
    {
        $body   = json_decode($request->getContent());
        $result = $this->settings->navSync($body);
        return response()->json($result)->header('Content-Type', 'application/json');
    }
}