<?php

namespace App\Nova\Resources\Ecommerce\Product\Review;

use App\Models\Ecommerce\Product\Review\Review as ReviewModel;
use App\Models\System\Settings\OS;
use App\Nova\Filters\VisableFilter;
use App\Nova\Resource;
use App\Nova\Resources\Ecommerce\Product\Product\Product;
use App\Nova\User;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Trin4ik\NovaSwitcher\NovaSwitcher;

class Review extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var class-string<ReviewModel>
     */
    public static $model = ReviewModel::class;

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

    /**
     * The relationships that should be eager loaded on index queries.
     *
     * @var array
     */
    public static $with = ['user', 'product'];

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

    /**
     * Get the displayable label of the resource.
     */
    public static function label(): string
    {
        return __('Reviews');
    }

    /**
     * Get the displayable singular label of the resource.
     */
    public static function singularLabel(): string
    {
        return __('Review');
    }

    /**
     * Get the fields displayed by the resource.
     */
    public function fields(NovaRequest $request): array
    {
        return [
            ID::make()->sortable(),

            BelongsTo::make(__('User'), 'user', User::class)
                ->searchable(),

            BelongsTo::make(__('Product'), 'product', Product::class)
                ->searchable(),

            Number::make(__('Rating'), 'rating')
                ->rules('required', 'integer', 'min:0', 'max:5'),

            Text::make(__('Title'), 'title')
                ->defaultStringRules(),

            Text::make(__('Content'), 'content')
                ->defaultStringRules()
                ->hideFromIndex(),

            Select::make(__('Source'), 'source')
                ->displayUsingLabels()
                ->searchable()
                ->options(OS::apps())
                ->default(OS::default())
                ->rules('required'),

            NovaSwitcher::make(__('Active'), 'is_visible')
                ->default(false),

            NovaSwitcher::make(__('Is recommended'), 'is_recommended')
                ->default(false),

            DateTime::make(__('Created at'), 'created_at')
                ->turkmenDate()
                ->exceptOnForms(),

            DateTime::make(__('Updated at'), 'updated_at')
                ->turkmenDate()
                ->exceptOnForms(),
        ];
    }

    /**
     * Get the cards available for the request.
     */
    public function cards(NovaRequest $request): array
    {
        return [];
    }

    /**
     * Get the filters available for the resource.
     */
    public function filters(NovaRequest $request): array
    {
        return [
            VisableFilter::make(),
        ];
    }

    /**
     * Get the lenses available for the resource.
     */
    public function lenses(NovaRequest $request): array
    {
        return [];
    }

    /**
     * Get the actions available for the resource.
     */
    public function actions(NovaRequest $request): array
    {
        return [];
    }
}
