<?php

namespace Modules\Mall\Http\Controllers\Admin\Action\Shop;

use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;
use Modules\Mall\Models\Shop;

class Reject extends RowAction
{

    public $name = '驳回申请';

    public function handle(Shop $shop, Request $request): Response
    {
        try {
            if ($shop->reject($request->reject_reason)) {
                return $this->response()->success('驳回申请成功')->refresh();
            } else {
                return $this->response()->error('驳回申请失败')->refresh();
            }
        } catch (\Exception $exception) {
            return $this->response()->error($exception->getMessage())->refresh();
        }
    }

    public function form()
    {
        $this->textarea('reject_reason', '驳回原因')->rules('required');
    }

}
