<?php

namespace Modules\User\Http\Controllers\Admin\Actions;

use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;
use Modules\User\Models\User;

class AddUserRemark extends RowAction
{

    public $name = '增加备注';

    public function handle(User $user, Request $request): Response
    {
        try {
            $user->addLog(Admin::user(), $request->remark);

            return $this->response()->success('添加备注成功')->refresh();
        } catch (\Exception $exception) {
            return $this->response()->error($exception->getMessage())->refresh();
        }
    }

    public function form(User $user)
    {
        $this->textarea('remark', '备注')->required();
    }

}