<?php

namespace Bixo\Payment\Http\Controllers;

use App\Http\Controllers\PublicController as BaseController;
use App\Http\Requests\PublicRequest;
use Litepie\Database\RequestScope;
use Bixo\Payment\Http\Resources\PaymentResource;
use Bixo\Payment\Http\Resources\PaymentsCollection;
use Bixo\Payment\Scopes\RefundPublicScope;
use Bixo\Payment\Models\Refund;

class RefundPublicController extends BaseController
{

    /**
     * Show refund's list.
     *
     * @return response
     */
    protected function index(PublicRequest $request)
    {

        $search = $request->search;
        $pageLimit = $request->input('pageLimit', config('database.pagination.limit'));
        $page = Refund::pushScope(new RequestScope())
            ->pushScope(new RefundPublicScope())
            ->paginate($pageLimit)
            ->withQueryString();

        $refunds = new RefundsCollection($page);

        $categories = [];
        $tags = [];
        $recent = [];

        return $this->response->setMetaTitle(trans('payment::refund.names'))
            ->view('payment::public.refund.index')
            ->data(compact('refunds', 'categories', 'tags', 'recent'))
            ->output();
    }

    /**
     * Show refund.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function show(PublicRequest $request, $slug)
    {
        $model = Refund::findBySlug($slug);
        $data = new RefundResource($model);

        $categories = [];
        $tags = [];
        $recent = [];
    
        return $this->response->setMetaTitle($data['title'] . trans('payment::refund.name'))
            ->view('payment::public.refund.show')
            ->data(compact('data', 'categories', 'tags', 'recent'))
            ->output();
    }

}