<?php

namespace Asadi\Payment\Http\Controllers;

use App\Http\Controllers\PublicController as BaseController;
use Asadi\Payment\Interfaces\PaymentRepositoryInterface;

class PaymentPublicController extends BaseController
{
    // use PaymentWorkflow;

    /**
     * Constructor.
     *
     * @param type \Asadi\Payment\Interfaces\PaymentRepositoryInterface $payment
     *
     * @return type
     */
    public function __construct(PaymentRepositoryInterface $payment)
    {
        $this->repository = $payment;
        parent::__construct();
    }

    /**
     * Show payment's list.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function index()
    {
        $payments = $this->repository
        ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria'))
        ->scopeQuery(function($query){
            return $query->orderBy('id','DESC');
        })->paginate();

        return $this->theme->of('payment::public.payment.index', compact('payments'))->render();
    }

    /**
     * Show payment.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function show($slug)
    {
        $payment = $this->repository->scopeQuery(function($query) use ($slug) {
            return $query->orderBy('id','DESC')
                         ->where('slug', $slug);
        })->first(['*']);

        return $this->theme->of('payment::public.payment.show', compact('payment'))->render();
    }

}