<?php

namespace App\Http\Controllers\Api\Frontend;

use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\Frontend\LandingTeacherRequest;
use App\Http\Resources\Frontend\LandingPageResource;
use App\Services\Frontend\LandingPageService;
use Illuminate\Http\JsonResponse;

class LandingPageController extends BaseApiController
{
    public function __construct(private LandingPageService $service)
    {
        parent::__construct();
    }

    public function index(LandingTeacherRequest $request): JsonResponse
    {
        $payload = $this->service->dashboardForUser(
            $request->user(),
            $request->validated()['class_section_id'] ?? null
        );

        return $this->success([
            'landing' => new LandingPageResource($payload),
        ]);
    }

    public function teacher(LandingTeacherRequest $request): JsonResponse
    {
        $payload = $this->service->teacher(
            $request->user(),
            $request->validated()['class_section_id'] ?? null
        );

        return $this->success([
            'landing' => new LandingPageResource($payload),
        ]);
    }

    public function parent(): JsonResponse
    {
        $payload = $this->service->parent(auth()->user());

        return $this->success([
            'landing' => new LandingPageResource($payload),
        ]);
    }

    public function administrator(): JsonResponse
    {
        $payload = $this->service->administrator();

        return $this->success([
            'landing' => new LandingPageResource($payload),
        ]);
    }

    public function admin(): JsonResponse
    {
        $payload = $this->service->admin();

        return $this->success([
            'landing' => new LandingPageResource($payload),
        ]);
    }

    public function student(): JsonResponse
    {
        $payload = $this->service->student();

        return $this->success([
            'landing' => new LandingPageResource($payload),
        ]);
    }

    public function guest(): JsonResponse
    {
        $payload = $this->service->guest();

        return $this->success([
            'landing' => new LandingPageResource($payload),
        ]);
    }
}
