<?php

namespace Modules\Client\Http\Controllers\Api;

use App\Helpers\Helper;
use App\Services\CorporateMemberService;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Client\Transformers\ClaimReport\MemberResources as ClaimReportMemberResources;
use Modules\Client\Transformers\Dashboard\MemberResources as DashboardMemberResources;
use Modules\Client\Transformers\Dashboard\MemberAlarmCenterResources as DashboardMemberAlarmResources;

class CorporateMemberController extends Controller
{
    public function __construct(public CorporateMemberService $corporateMemberService)
    {
    }

    /**
     * Display a listing of the resource.
     * @return Renderable
     */
    public function index(Request $request, $corporate_id)
    {
        switch ($request->input('type')) {
            case 'claim-report':
                $members = $this->corporateMemberService->getAllMemberClaimReports($corporate_id, $request);
                return response()->json(Helper::paginateResources(ClaimReportMemberResources::collection($members)));
            case 'claim-submit':
                $members = $this->corporateMemberService->getAllMemberClaimReports($corporate_id, $request);
                return response()->json(Helper::paginateResources(ClaimReportMemberResources::collection($members)));
            case 'alarm-center':
                $members = $this->corporateMemberService->getAllMemberAlarmCenter($corporate_id, $request);
                return response()->json(Helper::paginateResources(DashboardMemberAlarmResources::collection($members)));
            default:
                $members = $this->corporateMemberService->getAllMemberDashboards($corporate_id, $request);
                return response()->json(Helper::paginateResources(DashboardMemberResources::collection($members)));
        }
    }
}
