<?php

/**
 * @var $api \Dingo\Api\Routing\Router
 */
$api = app('Dingo\Api\Routing\Router');

$api->version('v1', ['namespace' => 'App\Http\Api\V1\Controllers', 'middleware' => ['cors','access-record']], function ($api) {
    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 调试类
    |-------------------------------------------------------------------------------------------------------------------
    */
    $api->any('test1', 'ToolsController@test1');
    $api->any('express', 'ToolsController@express');
    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 工具类
    |-------------------------------------------------------------------------------------------------------------------
    */
    $api->any('language', 'LanguageController@setLocale');

    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 短信消息通知回调
    |-------------------------------------------------------------------------------------------------------------------
    */
    $api->any('sms-notify', 'SmsController@notify')->name('sms.notify'); //

    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 订单支付回调:在三方平台支付成功后,回调处理
    |-------------------------------------------------------------------------------------------------------------------
   */
    $api->any('pay/notify/{type}', 'RechargeOrdersController@notifyPay')->name('pay.notify');

    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 微信授权相关:包含小程序和公众号
    |-------------------------------------------------------------------------------------------------------------------
    */
//    $api->group(['prefix' => 'wechat'], function ($api) {
//        $controller  = 'WechatController';
//        $prefix = 'wechat';
//        $api->any('mini-openid', $controller .'@getMiniOpenid')->name($prefix .'.user.openid');// 获取小程序 openid
//        $api->any('mini-authorized-login', $controller .'@authorizeLoginMini')->name($prefix .'.authorize.Login');// 小程序 授权登录
//        $api->any('mini-phone', $controller .'@getMiniPhone')->name($prefix .'.phone');// 获取小程序用户手机号
//
//
//        $api->post('auth/token', $controller .'@authLogin')->name($prefix .'.login');// 微信授权登录:根据 method 判断登录方式
//        $api->post('auth/token/nickname', $controller .'@authLoginByNickname')->name($prefix .'.auth.nickname');// 小程序昵称授权
//        $api->post('auth/token/mobile', $controller .'@authLoginByMobile')->name($prefix .'.auth.mobile');// 小程序手机号授权
//
//        $api->any('mini-openid', $controller .'@getMiniOpenid')->name($prefix .'.user.openid');// 获取小程序 openid
//        $api->any('login-with-nickname', $controller .'@authorizeLoginByNickname')->name($prefix .'.authorize.Login');// 小程序 授权登录
//        $api->any('login-with-mobile', $controller .'@authorizeLoginByMobile')->name($prefix .'.phone');// 获取小程序用户手机号
//
//        $api->any('mini-user', $controller .'@getMiniUserInfo')->name($prefix .'.user.info'); // 获取微信用户信息
//        $api->any('mini-decrypt', $controller .'@decrypt')->name($prefix .'decrypt'); // 解密
//        $api->any('token', $controller .'@token')->name($prefix .'.token');// 验证 token
//        $api->any('jssdk', $controller .'@jssdk')->name($prefix .'.jssdk');// 验证 token
//        $api->any('auth', $controller.'@auth')->name($prefix.'.authorize'); // 授权
//        $api->get('openid', $controller .'@initOpenid')->name($prefix .'.openid')->middleware('check.xcx.user');// 验证 token
//        $api->post('authorized-login', $controller .'@authorizeLogin')->name($prefix .'.authorize.Login')->middleware('check.xcx.user');// 授权登录
//        $api->post('openid', $controller .'@getOpenid')->name($prefix .'.user.openid')->middleware('check.xcx.user'); // 列表
//        $api->post('user', $controller .'@getWxUserInfo')->name($prefix .'.user.info'); // 列表
//        $api->post('server', $controller .'@server')->name($prefix .'.server');
//        $api->get('server', $controller .'@server')->name($prefix .'.server');
//    });

    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 用户信息
    |-------------------------------------------------------------------------------------------------------------------
    */
    $api->group(['namespace' => 'User'], function ($api) {
        /*
        |---------------------------------------------------------------------------------------------------------------
        | 用户模块
        |---------------------------------------------------------------------------------------------------------------
        */
        # 定义前缀
        $api->group(['prefix' => 'users',], function ($api) {
            // 用户信息
            $api->get('{id}', 'UsersController@show')->where('id', '[0-9]+');
            $api->get('detail', 'UsersController@detail');
        });
    });

    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 首页
    |-------------------------------------------------------------------------------------------------------------------
    */
    $api->any('home', 'HomesController@home')->name('home');

    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 工具类
    |-------------------------------------------------------------------------------------------------------------------
    */
    $api->group(['prefix' => 'utils'], function ($api) {
        $api->any('address', 'UtilsController@address');//
    });

    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 登录、注册、忘记密码 模块:微信授权相关,包含小程序和公众号
    |-------------------------------------------------------------------------------------------------------------------
    */
    $api->group(['prefix' => 'auth'], function ($api) {
        $api->post('token', 'AuthController@login');// 登录:根据 method 判断登录方式
        $api->post('user', 'AuthController@register');// 注册
        $api->post('login/quick', 'AuthController@loginQuick');// 快捷登录
        $api->post('password/reset', 'AuthController@resetPassword');// 重置密码
        $api->post('password/retrieve', 'AuthController@retrievePassword');// 找回密码
    });
    $api->post('sms-code', 'SmsController@store');// 发送验证码,用户注册:type1

//    $api->group(['middleware' => ['web','wechat.oauth']], function ($api) {
//        $api->post('auth', 'AuthController@wechatAuth')->name('user.authorize'); // 授权
//        $api->post('official-account', 'AuthController@wechatAuth')->name('user.authorize'); // 授权
//        $api->any('register', 'AuthController@register');// 注册
//    });
//
    $api->group(['middleware' => ['web']], function ($api) {
        $api->any('auth', 'AuthController@wechatAuth')->name('user.authorize'); // 授权
        $api->post('official-account', 'AuthController@wechatAuth')->name('user.authorize'); // 授权
        $api->any('register', 'AuthController@register');// 注册
    });

    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 需要用户登录后才能操作
    |-------------------------------------------------------------------------------------------------------------------
    */
    $api->group(['middleware' => 'jwt.api.auth'], function ($api) {
        /*
        |---------------------------------------------------------------------------------------------------------------
        | 登出
        |---------------------------------------------------------------------------------------------------------------
        */
        $api->post('logout', 'AuthController@logout');
        $api->delete('auth/token', 'AuthController@logout');

        /*
        |---------------------------------------------------------------------------------------------------------------
        | 用户模块
        |---------------------------------------------------------------------------------------------------------------
        */
        $api->group(['namespace' => 'User'], function ($api) {
            /*
            |-----------------------------------------------------------------------------------------------------------
            | 用户模块
            |-----------------------------------------------------------------------------------------------------------
            */
            # 定义前缀
            $api->group(['prefix' => 'users',], function ($api) {
                // 用户信息
                $api->get('me', 'UsersController@me'); // 我的信息
                $api->put('me', 'UsersController@updateMe'); // 更新我的信息
                $api->post('me', 'UsersController@submitMe'); // 游客-提交我的信息
                $api->any('account', 'UsersController@changeAccount'); // 更新我的账号
                // 我的钱包
                $api->get('wallet', 'UsersController@myWallet');
                // 我的团队
                $api->get('team-count', 'UsersController@myTeamCount');
                $api->get('team', 'UsersController@myTeam');
                $api->get('commissions', 'UsersController@myCommissions');
                $api->get('withdrawals', 'UsersController@myWithdrawals');
                $api->post('withdrawals', 'UsersController@withdrawal');
                // 收藏
                $api->get('favorites', 'UsersController@favorites');
                // 反馈
                $api->get('feedbacks', 'UsersController@myFeedbacks');
                // 消息
                $api->get('notifications', 'UsersController@myNotifications');
                $api->get('notifications-unread-count', 'UsersController@myUnreadNotificationsCount');
                // 次数记录
                $api->get('times-records', 'UsersController@myTimesRecords');
                // 聊天记录
                $api->get('chat-records', 'UsersController@myChatRecords');
                // 聊天记录
                $api->put('chat-records/cleared', 'UsersController@clearMyChatRecords');
            });

            /*
            |-----------------------------------------------------------------------------------------------------------
            | 用户地址模块
            |-----------------------------------------------------------------------------------------------------------
            */
            # 定义前缀
            $api->group(['prefix' => 'user-addresses'], function ($api) {
                $api->put('{id}/default', 'UserAddressesController@setDefault'); // 设置默认
            });
            $api->resource('user-addresses', 'UserAddressesController');
        });

        /*
        |---------------------------------------------------------------------------------------------------------------
        | 系统相关
        |---------------------------------------------------------------------------------------------------------------
        */
        $api->group(['namespace' => 'System'], function ($api) {
            /*
            |-----------------------------------------------------------------------------------------------------------
            | 系统参数相关
            |-----------------------------------------------------------------------------------------------------------
            */
            $api->group(['prefix' => 'system-configs'], function ($api) {
                $api->get('options', 'ConfigsController@options'); // options
            });

            /*
            |-----------------------------------------------------------------------------------------------------------
            | 系统参数相关
            |-----------------------------------------------------------------------------------------------------------
            */
            $api->get('system-setting', 'SettingsController@setting');

            $api->group(['prefix' => 'system-setting'], function ($api) {
                $api->get('options', 'SettingsController@options'); // options
            });

            /*
            |-----------------------------------------------------------------------------------------------------------
            | 系统轮播图
            |-----------------------------------------------------------------------------------------------------------
            */
            $api->group(['prefix' => 'system-banners'], function ($api) {
                $api->get('', 'SystemBannersController@all');
            });

            $api->get('system-banks', 'SystemsController@banks');
        });


//        /*
//        |---------------------------------------------------------------------------------------------------------------
//        | 分类 模块
//        |---------------------------------------------------------------------------------------------------------------
//        */
//        # 定义前缀
//        $api->group(['prefix' => 'categories'], function ($api) {
//            //
//            $api->get('{id}/examples', 'CategoriesController@examples');
//
//        });
//        $api->resource('categories', 'CategoriesController');


        /*
        |-----------------------------------------------------------------------------------------------------------
        | 意见反馈
        |-----------------------------------------------------------------------------------------------------------
        */
        $api->resource('feedbacks', 'FeedbacksController');

//        /*
//        |---------------------------------------------------------------------------------------------------------------
//        | 广告 模块
//        |---------------------------------------------------------------------------------------------------------------
//        */
//        # 定义前缀
//        $api->group(['prefix' => 'advertisements'], function ($api) {
//            //
//            $api->get('latest', 'AdvertisementsController@latest');
//        });
////        $api->resource('advertisements', 'AdvertisementsController');
//
//        /*
//        |---------------------------------------------------------------------------------------------------------------
//        | 帮助中心 模块
//        |---------------------------------------------------------------------------------------------------------------
//        */
////        $api->resource('help-centers', 'HelpCentersController');
//        $api->group(['prefix' => 'help-centers'], function ($api) {
//            $api->get('latest', 'HelpCentersController@latest');
//        });

        /*
        |---------------------------------------------------------------------------------------------------------------
        | 充值包 模块
        |---------------------------------------------------------------------------------------------------------------
        */
        $api->group(['prefix' => 'recharge-packages'], function ($api) {
            $api->post('{id}/orders', 'RechargePackagesController@recharge');
        });

        /*
        |---------------------------------------------------------------------------------------------------------------
        | 聊天 模块
        |---------------------------------------------------------------------------------------------------------------
        */
        $api->group(['prefix' => 'chat-records'], function ($api) {
            $api->post('{id}/items', 'ChatRecordsController@chat');
            $api->post('{id}/items/stream', 'ChatRecordsController@chatStream');
            $api->get('{id}/items', 'ChatRecordsController@items');
            $api->post('stream', 'ChatRecordsController@stream');
            $api->get('latest/timeout', 'ChatRecordsController@latestTimeout');
            $api->get('latest', 'ChatRecordsController@latest');
        });
        $api->resource('chat-records', 'ChatRecordsController');

    });

    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 系统相关
    |-------------------------------------------------------------------------------------------------------------------
    */
    $api->group(['namespace' => 'System'], function ($api) {

        $api->get('system-configs/options', 'ConfigsController@options'); // options
        $api->group(['prefix' => 'system-configs'], function ($api) {
            $api->get('express-companies', 'ConfigsController@expressCompanies');
        });
    });

    /*
    |-------------------------------------------------------------------------------------------------------------------
    | 分类 模块
    |-------------------------------------------------------------------------------------------------------------------
    */
    # 定义前缀
    $api->group(['prefix' => 'categories'], function ($api) {
        //
        $api->get('{id}/examples', 'CategoriesController@examples');
        $api->get('{id}/labels', 'CategoriesController@labels');

    });
    $api->resource('categories', 'CategoriesController');

    /*
     |---------------------------------------------------------------------------------------------------------------
     | 广告 模块
     |---------------------------------------------------------------------------------------------------------------
     */
    # 定义前缀
    $api->group(['prefix' => 'advertisements'], function ($api) {
        //
        $api->get('latest', 'AdvertisementsController@latest');
    });
    $api->resource('advertisements', 'AdvertisementsController');

    /*
    |---------------------------------------------------------------------------------------------------------------
    | 帮助中心 模块
    |---------------------------------------------------------------------------------------------------------------
    */
//        $api->resource('help-centers', 'HelpCentersController');
    $api->group(['prefix' => 'help-centers'], function ($api) {
        $api->get('latest', 'HelpCentersController@latest');
    });

    /*
    |---------------------------------------------------------------------------------------------------------------
    | 充值包 模块
    |---------------------------------------------------------------------------------------------------------------
    */
    $api->resource('recharge-packages', 'RechargePackagesController');
    $api->group(['prefix' => 'recharge-packages'], function ($api) {
        $api->get('latest', 'RechargePackagesController@latest');
    });
});