<?php

namespace App\Http\Controllers;

use App\Http\Requests\ManagementLinkRequest;
use App\Services\ManagementLinkService;
use App\Http\Requests\Member\ManagementLinkStore;

class ManagementLinkController extends Controller
{

    private $managementLinkService;

	public function __construct(ManagementLinkService $managementLinkService)
	{
		$this->managementLinkService = $managementLinkService;
	}

    public function index()
    {
        $management_links = $this->managementLinkService->getAll();

        return response()->json($management_links, 201);
    }

    public function store(ManagementLinkService $request)
    {
        $management_links = $this->managementLinkService->save($request->all());

        return response()->json($management_links, 201);
    }

    public function show($id)
    {
        $management_links = $this->managementLinkService->get($id);

        return response()->json($management_links);
    }

    public function destroy(ManagementLinkStore $request)
    {
      	$this->managementLinkService->delete($request->link_id);
        return response()->json(null, 204);
    }

    public function storeManagementLink(ManagementLinkStore $request) {
        $managementLink = [
            'member_id' => $request->member_id
        ];

        $link = $this->managementLinkService->save($managementLink);
        return response()->json($request, 201);
    }

    public function changeManagementLink(ManagementLinkStore $request) {
        $managementLink = [
            'id' => $request->link_id,
            $request->field => $request->value
        ];

        $link = $this->managementLinkService->save($managementLink);
        return response()->json($request, 201);
    }
}
