<?php

namespace App\Admin\Controllers;

use App\Model\User;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class UserController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('Index')
            ->description('description')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('Detail')
            ->description('description')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('Edit')
            ->description('description')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('Create')
            ->description('description')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new User);

        $grid->user_id('User id');
        $grid->name('Name');
        $grid->avatar('Avatar');
        $grid->cmcc_id('Cmcc id');
        $grid->mt('Mt');
        $grid->win_count('Win count');
        $grid->lose_count('Lose count');
        $grid->is_login('Is login');
        $grid->is_robot('Is robot');
        $grid->client_id('Client id');
        $grid->created_at('Created at');
        $grid->updated_at('Updated at');
        $grid->deleted_at('Deleted at');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(User::findOrFail($id));

        $show->user_id('User id');
        $show->name('Name');
        $show->avatar('Avatar');
        $show->cmcc_id('Cmcc id');
        $show->mt('Mt');
        $show->win_count('Win count');
        $show->lose_count('Lose count');
        $show->is_login('Is login');
        $show->is_robot('Is robot');
        $show->client_id('Client id');
        $show->created_at('Created at');
        $show->updated_at('Updated at');
        $show->deleted_at('Deleted at');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new User);

        $form->text('name', 'Name');
        $form->image('avatar', 'Avatar');
        $form->text('cmcc_id', 'Cmcc id');
        $form->text('mt', 'Mt');
        $form->number('win_count', 'Win count');
        $form->number('lose_count', 'Lose count');
        $form->switch('is_login', 'Is login');
        $form->switch('is_robot', 'Is robot');
        $form->text('client_id', 'Client id');

        return $form;
    }
}
