<?php

namespace Modules\User\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Services\Response\ResponseService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Modules\City\Services\CityService;
use Modules\Country\Services\CountryService;
use Modules\Order\Services\CartService;
use Modules\Region\Services\RegionService;
use Modules\User\Enums\AccountStatusEnum;
use Modules\User\Enums\AddressStatusEnum;
use Modules\User\Requests\Web\AddressRequest;
use Modules\User\Requests\Web\CardRequest;
use Modules\User\Requests\Web\ChangeCityRequest;
use Modules\User\Requests\Web\ChangeTypeRequest;
use Modules\User\Requests\Web\DeleteAddressRequest;
use Modules\User\Requests\Web\LoginRequest;
use Modules\User\Requests\Web\RegistRequest;
use Modules\User\Requests\Web\VerifyAddressRequest;
use Modules\User\Requests\Web\VerifyRequest;
use Modules\User\Requests\Web\EmailRequest;
use Modules\User\Services\AccountService;
use Modules\User\Services\AddressService;
use Modules\User\Services\UserService;

class PaymentController extends Controller
{
    private $viewDirectory = 'web.pages.profile.cards.';

    public function __construct(
        private UserService    $userService,
    ){}

    public function index()
    {
        $title = __('web.card');
        $user = auth()->user();
        $cards = $this->userService->cards($user->id);
        return view($this->viewDirectory . 'index', get_defined_vars());
    }

    public function create()
    {
        $title = __('web.add_card');
        $user = auth()->user();
        $action = route('web.card.create');
        return view($this->viewDirectory . 'form', get_defined_vars());
    }

    public function store(CardRequest $request)
    {
        $data = $request->validated();
        $data['user_id'] = auth()->user()->id;
        $this->userService->createCard($data);
        return ResponseService::response([
            'status'=>200,
            'message'=>__('web.success'),
            'data'=>route('web.card')
        ]);
    }

    public function destroy($id)
    {
        $this->userService->deleteCard($id);
        return redirect(route('web.payment'));
    }
}
