<?php

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

use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;
use Exception;
use Illuminate\Http\Request;
use Modules\User\Models\Identity;
use Modules\User\Models\Order;
use Modules\User\Models\User;

class SetTag extends RowAction
{

    public $name = '设置标签';

    public function handle(User $user, Request $request): Response
    {
        try {
            $tag = $request->tag;

            $user->update([
                'tag' => $tag
            ]);

            return $this->response()->success('加入标签成功')->refresh();
        } catch (Exception $e) {
            return $this->response()->error($e->getMessage())->refresh();
        }
    }

    public function form(User $user)
    {
        $this->select('tag', '标签')
            ->options(User::TAGS)
            ->required();
        $this->confirm('确认加入该标签？');
    }

}