<?php

/*
|--------------------------------------------------------------------------
| 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!
|
*/

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api) {
    /*
   |--------------------------------------------------------------
   |  不需要token验证的接口
   |--------------------------------------------------------------
   */
    $api->group([
        'middleware' => ['throttle:120'], //代表1分钟内接口最高请求次数，超出返回 429: Too Many Attempts
    ], function ($api) {

        $api->post('sms/send', 'SmsController@send'); //发送手机验证码
        $api->post('email/send', 'SmsController@sendEmailCode'); //发送邮箱验证码
        $api->post('attachment/upload', 'AttachmentController@upload'); //上传附件
        $api->post('attachment/delete', 'AttachmentController@delete'); //删除附件
        $api->get('privacy', 'IndexController@privacyPolice'); //隐私政策
        $api->get('agreement', 'IndexController@userAgreement'); //用户协议
    });

    $api->group(['prefix' => 'auth'], function ($api) {
        $api->post('login', 'AuthController@login');  //账号密码登录
        $api->post('wechat/minni/code', 'AuthController@wechatMiniCode'); //获取微信小程序 code
        $api->post('wechat/minni/phone', 'AuthController@wechatMiniPhone'); //获取微信小程序 code

    });

    $api->group(['prefix' => 'index'], function ($api) {
        $api->get('all_region', 'IndexController@allRegion'); //全国省市区
        $api->get('helps', 'IndexController@helpList'); //帮助类型
        $api->get('answer', 'IndexController@answer'); //问题答案
    });

    // 相关设置
    $api->group(['prefix' => 'setting'],function ($api){
        /* @var Dingo\Api\Routing\Router $api*/
        $api->get('login/banner', 'SettingController@loginBanner'); // banner
        $api->get('login/contact', 'SettingController@contact'); // contact
    });

    /*
 |--------------------------------------------------------------
 |  需要 token 验证的接口 'middleware' => ['api.auth'] 读取的 config/api.php  'auth' => ['jwt' => 'Dingo\Api\Auth\Provider\JWT'], 所以 在 Kernel.php 找不到这个中间件
 |--------------------------------------------------------------
 */
    $api->group([
        'middleware' => ['api.auth', 'throttle:120'],
    ], function ($api) {

        /* @var Dingo\Api\Routing\Router $api*/
        $api->post('auth/logout', 'AuthController@logout');  //退出登录
        $api->post('auth/forget_password', 'AuthController@forgetPassword'); //忘记密码

        $api->group(['prefix' => 'user'], function($api){
            /* @var Dingo\Api\Routing\Router $api*/
            $api->post('h5_bind', 'UserController@h5Bind'); //H5绑定
            $api->post('h5_rebind', 'UserController@h5Rebind'); //H5解绑
            $api->post('mini_program_bind', 'UserController@miniProgramBind'); //微信小程序绑定
            $api->post('mini_program_rebind', 'UserController@miniProgramReBind'); //微信小程序解绑
            $api->post('sms_bind', 'UserController@smsBind'); //手机号绑定
            $api->post('sms_rebind', 'UserController@smsReBind'); //手机号解绑
            $api->get('group_by_initial', 'UserController@groupByInitial'); //用户列表按照首字母分组排序，类似手机通讯录
            $api->post('feedback', 'UserController@feedback'); //问题反馈
            $api->get('info', 'UserController@info'); //用户信息
            $api->post('update', 'UserController@update'); //更新用户信息

        });

        // 相关设置
        $api->group(['prefix' => 'setting'],function ($api){
            /* @var Dingo\Api\Routing\Router $api*/
        });

        // 产品
        $api->group(['prefix' => 'product'],function ($api){
            /* @var Dingo\Api\Routing\Router $api*/
            $api->get('search', 'ProductController@search');
            $api->get('{id}/detail', 'ProductController@detail');
            $api->post('{id}/viewer', 'ProductController@viewer');
            $api->post('{id}/download', 'ProductController@download');
        });

        // 展厅案例
        $api->group(['prefix' => 'cases'],function ($api){
            /* @var Dingo\Api\Routing\Router $api*/
            $api->get('search', 'CasesController@search');
            $api->get('{id}/detail', 'CasesController@detail');
            $api->post('{id}/viewer', 'CasesController@viewer');
        });

    });

});
