<?php

namespace WeDevs\DokanVendorDashboard\REST;

use WeDevs\Dokan\Abstracts\DokanRESTController;
use WP_REST_Server;

class DashboardSettings extends DokanRESTController {

    /**
     * Endpoint namespace
     *
     * @var string
     */
    protected $namespace = 'dokan-vendor-dashboard/v1';

    /**
     * Route name
     *
     * @var string
     */
    protected $base = 'settings';

    /**
     * Register the routes.
     *
     * @since 1.0.4
     */
    public function register_routes() {
        register_rest_route(
            $this->namespace, '/' . $this->base, [
                [
                    'methods'             => WP_REST_Server::READABLE,
                    'callback'            => [ $this, 'get_settings' ],
                    'permission_callback' => 'is_user_logged_in',
                    'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::READABLE ),
                ],
                'schema' => [ $this, 'get_schema' ],
            ]
        );
    }

    public function get_schema() {
        $schema = [
            '$schema'              => 'http://json-schema.org/draft-04/schema#',
            'title'                => 'comment',
            'type'                 => 'object',
            'properties'           => [
                'usingSingleCategoryStyle' => [
                    'description'  => esc_html__( 'If category type is single', 'dokan-vendor-dashboard' ),
                    'type'         => 'boolean',
                    'context'      => [ 'view' ],
                    'readonly'     => true,
                ],
                'isSkuEnabled' => [
                    'description'  => esc_html__( 'Is sku enabled', 'dokan-vendor-dashboard' ),
                    'type'         => 'boolean',
                    'context'      => [ 'view' ],
                    'readonly'     => true,
                ],
                'isWeightEnabled' => [
                    'description'  => esc_html__( 'Is woocommerce weight enabled', 'dokan-vendor-dashboard' ),
                    'type'         => 'boolean',
                    'context'      => [ 'view' ],
                    'readonly'     => true,
                ],
                'isDimensionsEnabled' => [
                    'description'  => esc_html__( 'Is woocommerce dimension enabled', 'dokan-vendor-dashboard' ),
                    'type'         => 'boolean',
                    'context'      => [ 'view' ],
                    'readonly'     => true,
                ],
                'canManageStock' => [
                    'description'  => esc_html__( 'If can manage stock', 'dokan-vendor-dashboard' ),
                    'type'         => 'boolean',
                    'context'      => [ 'view' ],
                    'readonly'     => true,
                ],
                'shippingClasses' => [
                    'description'  => esc_html__( 'Woo-commerce shipping classes', 'dokan-vendor-dashboard' ),
                    'type'         => 'array',
                    'context'      => [ 'view' ],
                    'readonly'     => true,
                ],
            ],
        ];

        return apply_filters( 'dokan_vendor_dashboard_settings_schema', $this->add_additional_fields_schema( $schema ) );
    }

    public function get_settings() {
        $settings = [];

        return rest_ensure_response( $settings );
    }
}
