<?php

namespace App\Nova;

use App\Nova\Actions\declineVerificationRequest;
use App\Nova\Actions\VerifyWorker;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\MorphTo;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Laravel\Nova\Fields\URL;
use Laravel\Nova\Http\Requests\NovaRequest;

class VerificationRequest extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var class-string<\App\Models\VerificationRequest>
     */
    public static $model = \App\Models\VerificationRequest::class;
    public static $group = 'Users Group';
    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'entity.name';

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

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function fields(NovaRequest $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('name','entity.name')->hideWhenUpdating()->hideWhenCreating(),
            DateTime::make('created_at')->filterable()->sortable()->hideWhenUpdating(),
            MorphTo::make('worker','entity'),
            Boolean::make('action')->nullable()->filterable(),
            BelongsTo::make('action_by','user',User::class),
            Textarea::make('notes'),
//            URL::make('view profile',fn ()=>env('APP_URL'). $this->model->entity_type=='App\Models\Engineer'?'/e/':'/f/'. ),
        ];
    }

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

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

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

    /**
     * Get the actions available for the resource.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function actions(NovaRequest $request)
    {

        return [
            (VerifyWorker::make())->showInline()->withoutConfirmation(),
            declineVerificationRequest::make()->showInline(),
        ];
    }

    public function authorizedToDelete(Request $request): bool
    {
        return false;
    }
    public function authorizedToUpdate(Request $request): bool
    {
        return false;
    }
}
