<?php
use Illuminate\Support\Facades\Route;
use TPS\API\Http\Controllers\Addresses;
use TPS\API\Http\Controllers\Carts;
use TPS\API\Http\Controllers\Checkout;
use TPS\API\Http\Controllers\CMS;
use TPS\API\Http\Controllers\Customers;
use TPS\API\Http\Controllers\Categories;
use TPS\API\Http\Controllers\Channels;
use TPS\API\Http\Controllers\FilterOptions;
use TPS\API\Http\Controllers\Orders;
use TPS\API\Http\Controllers\Products;
use TPS\API\Http\Controllers\Reviews;
use TPS\API\Http\Controllers\Sliders;
use TPS\API\Http\Controllers\Wishlists;
use Webkul\RestApi\Http\Controllers\V1\Shop\Customer\InvoiceController;
use Webkul\RestApi\Http\Controllers\V1\Shop\Customer\ShipmentController;
use Webkul\RestApi\Http\Controllers\V1\Shop\Customer\TransactionController;

Route::group(['prefix' => 'api','middleware' => ['locale', 'currency']], function ($router) {
    /**
     * Core routes
     */
    Route::get('channels',[Channels::class, 'index']);
    Route::get('contacts',[CMS::class,'contacts']);
    Route::get('sliders',[Sliders::class, 'allResources']);
    Route::get('weeklyOffers',[Sliders::class, 'weeklyOffers']);
    /**
     * category routes
     */
    Route::get('descendant-categories', [Categories::class, 'index'])->name('descendant-categories');
    Route::get('category-brands/{id}', [Categories::class, 'brands']);
    Route::get('categories/{id}/filters',[Categories::class,'filters']);
    Route::get('attribute-options', [FilterOptions::class, 'allResources']);
    /**
     * Product routes.
     */
    Route::get('products', [Products::class, 'allResources']);
    Route::get('new-products', [Products::class, 'newProducts']);
    Route::get('featured-products', [Products::class, 'featuredProducts']);
    Route::get('products-discounted', [Products::class, 'discountedProducts']);
    Route::get('products/{id}', [Products::class, 'getResource']);
    Route::get('products/{id}/additional-information', [Products::class, 'additionalInformation']);
    Route::get('products/{id}/configurable-config', [Products::class, 'configurableConfig']);
    Route::get('products/{id}/variants', [Products::class, 'variants']);
    Route::get('products/{id}/reviews', [Reviews::class, 'productReviews']);
    /*
     * CMS pages
     */
    Route::get('cms',[CMS::class,'allResources']);
    Route::get('cms/{id}', [CMS::class, 'getResource']);

    /**
     * Customer auth routes.
     */
    Route::post('customer/login', [Customers::class, 'login']);
    Route::post('customer/register', [Customers::class, 'register']);
    Route::post('customer/reset_password', [Customers::class, 'resetPassword']);
    Route::post('customer/update_password', [Customers::class, 'updatePassword']);

    Route::group(['middleware' => ['auth:sanctum', 'sanctum.customer'],'prefix' =>'customer'], function () {

        Route::put('profile', [Customers::class, 'update']);
        Route::delete('delete', [Customers::class, 'destroy']);
        /**
         * Customer address routes.
         */
        Route::get('addresses', [Addresses::class, 'index']);
        Route::post('addresses', [Addresses::class, 'create']);
        Route::get('addresses/{id}', [Addresses::class, 'show']);
        Route::put('addresses/{id}', [Addresses::class, 'update']);
        Route::delete('addresses/{id}', [Addresses::class, 'destroy']);
        /**
         * Customer wishlist routes.
         */
        Route::get('wishlist', [Wishlists::class, 'index']);
        Route::post('wishlist/{id}', [Wishlists::class, 'addOrRemove']);
        Route::post('wishlist/{id}/move-to-cart', [Wishlists::class, 'moveToCart']);
        /**
         * Customer cart routes.
         */
        Route::get('cart', [Carts::class, 'get']);
        Route::post('cart/add/{productId}', [Carts::class, 'add']);
        Route::put('cart/update', [Carts::class, 'update']);
        Route::delete('cart/remove/{cartItemId}', [Carts::class, 'removeItem']);
        Route::delete('cart/empty', [Carts::class, 'empty']);
        Route::post('cart/move-to-wishlist/{cartItemId}', [Carts::class, 'moveToWishlist']);
        Route::post('cart/coupon', [Carts::class, 'applyKupon']);
        Route::delete('cart/coupon', [Carts::class, 'removeCoupon']);

        /**
         * Customer checkout routes.
         */
        Route::post('checkout/save-address', [Checkout::class, 'saveAddress']);
        Route::post('checkout/save_shipping', [Checkout::class, 'saveShipping']);
        Route::post('checkout/save-payment', [Checkout::class, 'savePayment']);
        Route::post('checkout/check-minimum-order', [Checkout::class, 'checkMinimumOrder']);
        Route::post('checkout/save-order', [Checkout::class, 'saveOrder']);

        /**
         * Customer sale routes.
         */
        Route::get('orders', [Orders::class, 'allResources']);
        Route::get('orders/{id}', [Orders::class, 'getResource']);
        Route::post('orders/{id}/cancel', [Orders::class, 'cancel']);
        Route::get('invoices', [InvoiceController::class, 'allResources']);
        Route::get('invoices/{id}', [InvoiceController::class, 'getResource']);
        Route::get('shipments', [ShipmentController::class, 'allResources']);
        Route::get('shipments/{id}', [ShipmentController::class, 'getResource']);
        Route::get('transactions', [TransactionController::class, 'allResources']);
        Route::get('transactions/{id}', [TransactionController::class, 'getResource']);

        /**
         * Reviews.
         */
        Route::get('reviews', [Reviews::class, 'allResources'])->name('api.customer.reviews.index');
        Route::post('reviews/create/{id}', [Reviews::class, 'store'])->name('api.customer.reviews.create');
        Route::delete('reviews/delete/{id}', [Reviews::class, 'destroyResource'])->name('api.customer.review.delete');

    });

});
