<?php

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

use App\Models\Ecommerce\Product\Order\Shipping\OrderShippingMethod as OrderShippingMethodModel;
use App\Nova\Resource;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Laravel\Nova\Http\Requests\NovaRequest;
use Trin4ik\NovaSwitcher\NovaSwitcher;

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

    /**
     * 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', 'slug',
    ];

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

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

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

            Text::make(__('Name'), 'name')
                ->translatable()
                ->rules('required', 'max:255'),

            Text::make(__('Slug'), 'slug')
                ->hideWhenCreating()
                ->hideWhenUpdating()
                ->rules('nullable', 'string', 'max:255'),

            Textarea::make(__('Description'), 'description')
                ->translatable()
                ->rules('nullable', 'max:1000'),

            Number::make(__('Price'), 'price')
                ->step(0.01)
                ->rules('required', 'numeric', 'min:0'),

            NovaSwitcher::make(__('Is active'), 'is_active')
                ->default(true),
        ];
    }
}
