<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\CreateProdukTabunganRequest;
use App\Http\Requests\UpdateProdukTabunganRequest;
use App\Services\TabunganService;
use Exception;

class ProdukTabunganController extends Controller
{
    protected $tabunganService;

    public function __construct(TabunganService $tabunganService)
    {
        $this->tabunganService = $tabunganService;
    }

    public function index()
    {
        return $this->tabunganService->getAllProduk();
    }

    public function create()
    {
        //
    }

    public function store(CreateProdukTabunganRequest $request)
    {
        $validated = $request->validated();
        return $this->tabunganService->createProduk($validated);
    }

    public function show(string $id)
    {
        return $this->tabunganService->findProdukById($id);
    }

    public function edit(string $id)
    {
        //
    }

    public function update(UpdateProdukTabunganRequest $request, string $id)
    {
        $validatedData = $request->validated();
        return $this->tabunganService->updateProduk($id, $validatedData);
    }

    public function destroy(string $id)
    {
        return $this->tabunganService->deleteProdukTabungan($id);
    }
}
