<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Models\Transaction;
use App\Models\Validate;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;

class DepositController extends Controller
{
    public function bank(){
        if(config('settings.enable_deposits')==1){
            return view('user.bank-deposit');
        }
        return redirect(route('user.dashboard'));
    }

    public function blockchain(){
        if(config('settings.enable_deposits')==1){
            return view('user.crypto-deposit');
        }
        return redirect(route('user.dashboard'));
    }

    public function create(Request $request){
        $validator = Validator::make($request->all(),Validate::$DepositForm);
        if($validator->fails()){
            throw ValidationException::withMessages([__($validator->errors()->first())]);
        }
        $tx = Transaction::create([
            'user_id'=>auth()->user()->id,
            'tx_id'=>Transaction::generateTxId(),
            'type' => 'deposit',
            'category' => $request->type,
            'bank_name'=>config('settings.site_name'),
            'receiver_name'=>auth()->user()->lastname.' '.auth()->user()->firstname,
            'receiver_account'=>auth()->user()->account->account_number,
            'remark'=>$request->description,
            'amount'=>$request->amount,
        ]);
        //TODO: SEND MAIL TO CUSTOMER
        $msgBody = [

        ];
        return redirect()->back()->with('success',__('Your deposit request has been received and is under review. Do not submit again. you can <a href="'.route('user.transfer.international').'">check the status of your deposit here!</a>'));
    }
}
