<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Services\ClientGroupService;
use Illuminate\Http\Request;

class ClientGroupController extends Controller
{
    protected ClientGroupService $service;

    public function __construct(ClientGroupService $service)
    {
        $this->service = $service;
    }

    public function index(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            $data = $this->service->index($request->all());

            return ['data' => $data, 'message' => __('message.fetched')];
        });
    }

    public function show(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            $data = $this->service->show($id);

            return ['data' => $data, 'message' => __('message.fetched')];
        });
    }

    public function store(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            $data = $this->service->store($request->all());

            return ['data' => $data, 'message' => __('message.created')];
        });
    }

    public function update(Request $request, int $id)
    {
        return ApiResponse::handle(function () use ($request, $id) {
            $data = $this->service->update($id, $request->all());

            return ['data' => $data, 'message' => __('message.updated')];
        });
    }

    public function destroy(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            $this->service->destroy($id);

            return ['data' => null, 'message' => __('message.deleted')];
        });
    }

    public function toggle(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            $data = $this->service->toggle($id);

            return ['data' => $data, 'message' => __('message.updated')];
        });
    }
}
