<?php

namespace Modules\Linksehat\Http\Controllers\Api;

use App\Helpers\Helper;
use App\Models\Practice;
use App\Models\PractitionerRole;
use App\Models\Speciality;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Linksehat\Transformers\Speciality\SpecialityResource;
use Symfony\Component\HttpFoundation\Response;

class SpecialityController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Renderable
     */
    // public function index(Request $request)
    // {
    //     $organizationId = $request->organization_id;
    //     $specialityId = $request->speciality_id;

    //     if (empty($organizationId) || empty($specialityId)) {
    //         $messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or ';
    //         $messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id';

    //         abort(Response::HTTP_BAD_REQUEST, 'Missing Parameter' . $messageorganizationId . $messageSpecialityId);
    //     }

    //     $doctors = PractitionerRole::query()
    //         ->with(['practitioner.person', 'speciality', 'prices'])
    //         ->whereHas('prices', function ($query) {
    //             $query->where('priceable_type', Practice::class);
    //         })
    //         ->where('organization_id', $organizationId)
    //         ->where('speciality_id', $specialityId)
    //         ->get();

    //     abort_if(count($doctors) === 0, Response::HTTP_NOT_FOUND, 'Data Doctor tidak ditemukan');

    //     foreach ($doctors as $key => $doctor) {
    //         $specialisName = $doctor->speciality->name;
    //     }

    //     return Helper::responseJson([
    //         'title' => 'Spesialis ' . $specialisName,
    //         'doctors' => SpecialityResource::collection($doctors)
    //     ]);
    // }

    public function index()
    {
        $specialities = Speciality::query()->get();

        return Helper::responseJson(['specialities' => $specialities]);
    }
}
