<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Settings\UpdateHomepageRequest;
use App\Http\Requests\Admin\Settings\UpdateHRRequest;
use App\Http\Requests\Admin\Settings\UpdateSocialMediaRequest;
use App\Http\Requests\Admin\Settings\UpdateSystemRequest;
use App\Services\Admin\AdminSettingsService;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Inertia\Response;

class AdminSettingsController extends Controller
{
    public function __construct(
        private AdminSettingsService $service
    ) {}

    public function index(): Response
    {
        return Inertia::render('admin/settings/index', [
            'system' => $this->service->getSystemData(),
            'homepage' => $this->service->getHomepageData(),
            'socialMedia' => $this->service->getSocialMediaData(),
            'hr' => $this->service->getHRData(),
        ]);
    }

    public function updateSystem(UpdateSystemRequest $request): RedirectResponse
    {
        $this->service->updateSystem($request->validated());

        Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan sistem berhasil diperbarui.']);

        return back();
    }

    public function updateHomepage(UpdateHomepageRequest $request): RedirectResponse
    {
        $this->service->updateHomepage($request->validated());

        Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan homepage berhasil diperbarui.']);

        return back();
    }

    public function updateSocialMedia(UpdateSocialMediaRequest $request): RedirectResponse
    {
        $this->service->updateSocialMedia($request->validated());

        Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan media sosial berhasil diperbarui.']);

        return back();
    }

    public function updateHR(UpdateHRRequest $request): RedirectResponse
    {
        $this->service->updateHR($request->validated());

        Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengaturan HR berhasil diperbarui.']);

        return back();
    }
}
