<?php

namespace Bixo\Payment\Http\Controllers;

use App\Http\Controllers\ActionController as BaseController;
use Exception;
use Bixo\Payment\Actions\DetailAction;
use Bixo\Payment\Http\Requests\DetailActionRequest;
use Bixo\Payment\Http\Resources\DetailResource;
use Bixo\Payment\Models\Detail;

/**
 * Admin web controller class.
 */
class DetailActionController extends BaseController
{

    /**
     * Action controller function for detail.
     *
     * @param Model $model
     * @param action next action for the model.
     *
     * @return Response
     */
    public function __invoke(DetailActionRequest $request, Detail $detail, $action)
    {
        try {
            $request = $request->all();
            $detail = DetailAction::run($action, $detail, $request);

            $data = new DetailResource($detail);
            return $this->response->message(trans("messages.success.{$action}", ['Module' => trans('payment::detail.name')]))
                ->code(204)
                ->data(compact('data'))
                ->status('success')
                ->url(guard_url('payment/detail/' . $detail->getRouteKey()))
                ->redirect();
        } catch (Exception $e) {
            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('payment/detail/' . $detail->getRouteKey()))
                ->redirect();
        }
    }

    public function notify(){
        
    }
}