<?php

namespace Modules\HospitalPortal\Http\Controllers\Api;

use App\Helpers\Helper;
use App\Models\Member;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

class MemberController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Renderable
     */
    public function search(Request $request)
    {
        $request->validate([
            'no_polis' => 'required',
            'birth_date' => 'required'
        ]);

        $member = Member::query()
                        ->where('member_id', $request->no_polis)
                        ->where('birth_date', $request->birth_date)
                        ->with(['person', 'currentCorporate', 
                            // 'currentCorporate.corporateServices' => function ($corporateService) {
                            //     $corporateService->where('status', 'active');
                            // }, 
                            // 'currentCorporate.corporateServices.service'
                            // 'currentPlan.benefits',
                            // 'currentPlan.corporateBenefit.plan',
                            'currentPlan.corporateBenefits.benefit'
                        ])
                        ->firstOrFail();

            
        return Helper::responseJson($member);
    }
}
