<?php

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\BelongsToMany;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\Gravatar;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Password;
use Laravel\Nova\Fields\Text;

class Academy extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = \App\Models\Academy::class;

    public static $perPageOptions = [50, 100, 150];

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'name';

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id',
        'name',
        'url',
        'code'
    ];

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function fields(Request $request)
    {

        return [
            ID::make()->sortable(),

            Text::make('Name')
                ->sortable()
                ->rules('required', 'max:255'),

            Text::make('Academy duration (ex. 6months)', 'length')
                ->sortable()
                ->rules('required', 'max:255'),

            Text::make('Start Date')
                ->rules('required')
                ->sortable(),

            Text::make('Assessment duration (seconds, ex. 1500)', 'duration')
                ->sortable()
                ->rules('required', 'numeric'),

            Text::make('Memory matrix duration (seconds, ex. 1500)', 'memory_matrix_duration')
                ->sortable()
                ->rules('required', 'numeric'),

            Text::make('Speed Arithmetic duration (seconds, ex. 1500)', 'speed_arithmetic_duration')
                ->sortable()
                ->rules('required', 'numeric'),

            Text::make('Url')
                ->creationRules('required', 'string', 'url')
                ->updateRules('required', 'string', 'url'),

            Text::make('Code')
                ->sortable()
                ->rules('required', 'max:64'),

            BelongsToMany::make('Question Types')
                ->fields(function () {
                    return [
                        Number::make('Amount')
                            ->rules('required', 'numeric'),
                    ];
                }),
        ];
    }

    /**
     * Get the cards available for the request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function cards(Request $request)
    {
        return [];
    }

    /**
     * Get the filters available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function filters(Request $request)
    {
        return [];
    }

    /**
     * Get the lenses available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function lenses(Request $request)
    {
        return [];
    }

    /**
     * Get the actions available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function actions(Request $request)
    {
        return [];
    }
}
