<?php

use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Role\RolesController;
use App\Http\Controllers\UploadController;
use App\Http\Controllers\Shop\ShopsController;
use App\Http\Controllers\Goods\GoodsSkusController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware(['auth:api', 'check.permissions'])->group(function () {
    // 用户
    Route::resource('users', 'User\UsersController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]);
    // 商品种类
    Route::resource('goods_types', 'Goods\GoodsTypesController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]);
    // 商品品牌
    Route::resource('goods_brands', 'Goods\GoodsBrandsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]);
    // 日志
    Route::resource('logs', 'Log\LogsController', ['only' => ['index']]);
    // 商品
    Route::resource('goods', 'Goods\GoodsController', ['only' => ['index', 'store']]);
    // 商品规格
    Route::resource('goods_skus', 'Goods\GoodsSkusController', ['only' => ['index', 'show', 'update', 'store']]);
    Route::patch('batch/goods_skus', [GoodsSkusController::class, 'batchUpdate'])->name('goods_sku.batch_update');
    Route::patch('single/goods_skus/{id}', [GoodsSkusController::class, 'updateField'])->name('goods_sku.single_update');
    // 店铺
    Route::resource('shops', 'Shop\ShopsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]);
    Route::get('count/orders/num', [ShopsController::class, 'countOrdersNumWithSkuCode'])->name('goods_sku.orders_num');
    Route::get('download/{id}/goods', [ShopsController::class, 'downloadGoods'])->name('business.goods_sku.download');
    // 角色
    Route::resource('roles', 'Role\RolesController', ['only' => ['index', 'store', 'show', 'update']]);
    Route::post('roles/{id}/permissions', [RolesController::class, 'addPermissions'])->name('roles.permission');
    // 权限
    Route::resource('permissions', 'Permission\PermissionsController', ['only' => ['index',
//        'store', 'show', 'update', 'destroy'
    ]]);
    Route::post('upload', [UploadController::class, 'store'])->name('upload.file');
});

Route::post('/auth/login', [LoginController::class, 'login'])->name('auth.login');

// 菜单
Route::resource('menus', 'Menu\MenusController', ['only' => ['index',
//        'store', 'show', 'update', 'destroy'
]])->middleware('auth:api');

Route::get('shop_platforms', [ShopsController::class, 'getPlatList'])->name('plat.list')->middleware('auth:api');

Route::post('business', [ShopsController::class, 'business'])->name('shop.put.business');
