<?php

namespace App\Http\Controllers\Api\App\Wallet;

use App\Http\Controllers\Controller;
use App\Http\Requests\Api\App\Wallet\DepositRequest;
use App\Http\Resources\Api\App\Wallet\{PackageResource, TransactionResource, WalletResource};
use App\Models\Package;
use App\Services\WalletService;

class WalletController extends Controller
{
    private $wallet_service;

    public function __construct()
    {
        $this->wallet_service = new WalletService();
    }

    public function wallet()
    {
        return WalletResource::make($this->wallet_service->getWallet())->additional(['status' => 'success', 'message' => '']);
    }

    public function transactions()
    {
        return TransactionResource::collection($this->wallet_service->getTransactions())->additional(['status' => 'success', 'message' => '']);
    }

    public function deposit(DepositRequest $request)
    {
        $validated = $request->validated();
        $deposit   = $this->wallet_service->deposit(amount: $validated['amount'], modelable_type: $validated['modelable_type'], modelable_id: $validated['modelable_id']);
        if ($deposit) return response()->json(['status' => 'success', 'data' => null, 'message' => trans('The deposit has been successfully added to your wallet')]);
        return response()->json(['status' => 'fail', 'data' => null, 'message' => ''], 422);
    }
}
