<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\ArticleController;

/*
|--------------------------------------------------------------------------
| 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')->get('/user', function (Request $request) {
//    return $request->user();
//});

$api = app('Dingo\Api\Routing\Router');
//这里的version是版本，里面的v1是在env里面定义好的。
$api->version('v1', function($api) {
    $api->get('gzh', function(){
        return view('gzh');
//        return 'this is test dingo api';
    });
    $api->get('dist', function(){
        return view('dist');
    });

//    $api->group(['prefix'=>'login'], function ($api) {
//        $api->post('login', [LoginController::class,'login'])->name('login');
//        $api->post('register', [LoginController::class,'register']);
//        $api->group(['middleware' => 'auth:users'],function($api){
//            $api->get('logout', [LoginController::class,'logout']);
//            $api->get('user', [LoginController::class,'getAuthUser']);
//        });
//    });
//
//    $api->group(['prefix'=>'article'], function ($api) {
//        $api->get('list', [ArticleController::class,'list']);
//        $api->get('detail', [ArticleController::class,'detail']);
//        $api->group(['middleware' => 'auth:users'],function($api){
////        $api->group(['middleware' => 'check_token'],function($api){
//            $api->get('getDataInfo', [ArticleController::class,'getDataInfo']);
//            $api->post('like', [ArticleController::class,'like']);
//            $api->post('share', [ArticleController::class,'share']);
//            $api->post('read', [ArticleController::class,'read']);
//            $api->post('addComment', [ArticleController::class,'addComment']);
//            $api->get('getSignPackage', [ArticleController::class,'getSignPackage']);
//            $api->get('getArticleLike', [ArticleController::class,'getArticleLike']);
//            $api->get('getWetalkData', [ArticleController::class,'getWetalkData']);
//            $api->get('getAllWetalkComment', [ArticleController::class,'getAllWetalkComment']);
//        });
//    });

    $api->group(['prefix'=>'admin','namespace'=>'App\Http\Controllers\Admin'], function($api){
        $api->post('login','LoginController@login')->name('login');
        $api->post('register','LoginController@register');
        $api->post('refresh', 'LoginController@refresh')->name('refresh');
        $api->group(['middleware' => ['check_token','auth:admins']],function($api) {
            $api->get('getAuthUserT', 'LoginController@getAuthUser');
        });
        $api->group(['middleware' => ['check_token','auth:admins']],function($api) {
            $api->get('getAuthUser', 'LoginController@getAuthUser');
            $api->get('list', 'LoginController@list');
            $api->post('delete', 'LoginController@delete');
            $api->post('edit', 'LoginController@edit');
            $api->post('logout', 'LoginController@logout');
        });
        $api->group(['prefix'=>'article'], function ($api) {
            $api->get('list', 'ArtController@list');
            $api->get('detail', 'ArtController@detail');
            $api->get('downAudioFile', 'ArtController@downAudioFile');
            $api->group(['middleware' => ['check_token','auth:admins']],function($api){//'check_token'
                $api->post('uploadAudio', 'ArtController@uploadAudio');
                $api->post('uploadAudioSimple', 'ArtController@uploadAudioSimple');
                $api->post('continueUploadAudio', 'ArtController@continueUploadAudio');
                $api->post('editArticle', 'ArtController@editArticle');
                $api->post('editArticleContent', 'ArtController@editArticleContent');
                $api->get('getArticleListNum', 'ArtController@getArticleListNum');
                $api->get('getArticleList', 'ArtController@getArticleList');
                $api->get('getArticleDetail', 'ArtController@getArticleDetail');
                $api->post('uploadImg', 'ArtController@uploadImg');
                $api->post('deleteArticle', 'ArtController@deleteArticle');
                $api->post('manualRelease', 'ArtController@manualRelease');
                $api->post('cancelShelvesArticle', 'ArtController@cancelShelvesArticle');
                $api->get('getCommentList', 'ArtController@getCommentList');
                $api->post('authComment', 'ArtController@authComment');
                $api->get('getArticleComment', 'ArtController@getArticleComment');
                $api->post('uploadBackgroundMusic', 'ArtController@uploadBackgroundMusic');
                $api->post('addBackgroundMusic', 'ArtController@addBackgroundMusic');
                $api->post('editBackgroundMusic', 'ArtController@editBackgroundMusic');


//                $api->get('sendSms', 'ArtController@sendSms');
                $api->get('getAllPhone', 'ArtController@getAllPhone');
                $api->post('addPhone', 'ArtController@addPhone');
                $api->post('deletePhone', 'ArtController@deletePhone');

                $api->get('getData', 'ArtController@getData');
                $api->get('ddd', 'ArtController@ddd');
            });
        });
        $api->group(['prefix'=>'data'], function ($api) {
            $api->group(['middleware' =>  ['check_token','auth:admins']],function($api){
                $api->get('index', 'DataController@index');
                $api->get('getArticleRead', 'DataController@getArticleRead');
            });
        });

        //不验证token
        $api->group(['prefix' => 'check'],function($api) {
            $api->post('login','LoginController@login')->name('login');
            $api->post('register','LoginController@register');
            $api->post('refresh', 'LoginController@refresh')->name('refresh');

            $api->get('getAuthUserT', 'LoginController@getAuthUser');

            $api->get('getAuthUser', 'LoginController@getAuthUser');
            $api->get('list', 'LoginController@list');
            $api->post('delete', 'LoginController@delete');
            $api->post('edit', 'LoginController@edit');
            $api->post('logout', 'LoginController@logout');

            $api->group(['prefix' => 'article'], function ($api) {
                $api->get('list', 'ArtController@list');
                $api->get('detail', 'ArtController@detail');
                $api->post('uploadAudio', 'ArtController@uploadAudio');
                $api->post('uploadAudioSimple', 'ArtController@uploadAudioSimple');
                $api->post('continueUploadAudio', 'ArtController@continueUploadAudio');
                $api->post('editArticle', 'ArtController@editArticle');
                $api->post('editArticleContent', 'ArtController@editArticleContent');
                $api->get('getArticleListNum', 'ArtController@getArticleListNum');
                $api->get('getArticleList', 'ArtController@getArticleList');
                $api->get('getArticleDetail', 'ArtController@getArticleDetail');
                $api->post('uploadImg', 'ArtController@uploadImg');
                $api->post('deleteArticle', 'ArtController@deleteArticle');
                $api->post('manualRelease', 'ArtController@manualRelease');
                $api->post('cancelShelvesArticle', 'ArtController@cancelShelvesArticle');
                $api->get('getCommentList', 'ArtController@getCommentList');
                $api->post('authComment', 'ArtController@authComment');
                $api->get('getArticleComment', 'ArtController@getArticleComment');
                $api->post('uploadBackgroundMusic', 'ArtController@uploadBackgroundMusic');
                $api->post('addBackgroundMusic', 'ArtController@addBackgroundMusic');
                $api->post('editBackgroundMusic', 'ArtController@editBackgroundMusic');
//                $api->get('sendSms', 'ArtController@sendSms');
                $api->get('getAllPhone', 'ArtController@getAllPhone');
                $api->post('addPhone', 'ArtController@addPhone');
                $api->post('deletePhone', 'ArtController@deletePhone');

                $api->get('getData', 'ArtController@getData');
                $api->get('ddd', 'ArtController@ddd');
            });
            $api->group(['prefix' => 'data'], function ($api) {
                $api->get('index', 'DataController@index');
                $api->get('getArticleRead', 'DataController@getArticleRead');
            });
        });
    });
});
