<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\V1\Ai\AiController;
// Router::addRoute(['GET', 'POST', 'HEAD'], '/api/wechat/pay/aiCallback', 'App\Http\Controllers\V1\PayNoticeController@wechat');
// Route::middleware(['apiLogs'])->group(function () {
//    Route::any('/buildStory',[AiController::class,'buildStory']);
// });
// Route::post('/buildStory',[AiController::class,'buildStory']);
$api = app('Dingo\Api\Routing\Router');

$api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api) {
    /*
   |--------------------------------------------------------------
   |  不需要token验证的接口
   |--------------------------------------------------------------
   */

    $api->group([
        'middleware' => ['apiLogs', 'throttle:120'], // 代表1分钟内接口最高请求次数，超出返回 429: Too Many Attempts
    ], function ($api) {
           $api->post('wechat/pay/aiCallback', 'PayNoticeController@wechat'); // banner
        //        $api->post('buildStory', 'Ai/AiController@send'); //发送手机验证码
        $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->get('getHandpick', 'IndexController@getHandpick'); // 用户协议
        $api->get('payConfig', 'IndexController@payConfig'); // 用户协议
        $api->post('avatar/upload', 'UserController@upload'); // 上传
        $api->get('banner', 'SettingController@banner'); // banner
        $api->get('getServiceConfig', 'IndexController@getServiceConfig'); // banner
        $api->get('getConfigByKey', 'IndexController@getConfigByKey'); // 通过key获取配置
    });
    $api->group(['namespace' => 'Ai'], function ($api) {
        /* @var Dingo\Api\Routing\Router $api */
        // 观看记录相关
        $api->group(['prefix' => 'ai'], function ($api) {
            /* @var Dingo\Api\Routing\Router $api */
            $api->any('buildStory', 'AiController@buildStory');
            $api->any('buildTitle', 'AiController@buildTitle');
            $api->any('buildKeyword', 'AiController@buildKeyword');
            $api->any('buildSd', 'AiController@buildSd');
            $api->any('getOpensdDetail', 'AiController@getOpensdDetail');
            $api->any('generate_pdf', 'AiController@generate_pdf');
            $api->any('buildPinyin', 'AiController@buildPinyin');
            $api->get('Pinyin', 'AiController@Pinyin');
        });
    });
    $api->group(['prefix' => 'auth'], function ($api) {
        $api->post('login', 'AuthController@login');  // 账号密码登录
        $api->post('register', 'AuthController@register'); // 注册
        $api->post('auth_login', 'AuthController@authLogin'); // APP第三方授权登录(微信)
        $api->post('decrypt_phone', 'AuthController@decryptPhone'); // 微信小程序获取手机号
        $api->post('h5_oauth', 'AuthController@h5Oauth'); // H5授权登录
        $api->post('mini_program', 'AuthController@miniProgram'); // 微信小程序登录(微信)
        $api->get('mini_code', 'AuthController@miniCode'); // 获取微信小程序 code
        $api->post('bytedance', 'AuthController@bytedance'); // 获取字节跳动小程序 code
        $api->post('kuaishou', 'AuthController@kuaishou'); // 获取快手小程序 code
        $api->post('wechat', 'AuthController@wechat'); // 获取微信小程序 code
    });

    $api->group(['prefix' => 'index'], function ($api) {
        $api->get('all_region', 'IndexController@allRegion'); // 全国省市区
        $api->get('helps', 'IndexController@helpList'); // 帮助类型
        $api->get('answer', 'IndexController@answer'); // 问题答案
    });
    $api->any('test', 'TestController@index'); // test api
    /*
 |--------------------------------------------------------------
 |  需要 token 验证的接口 'middleware' => ['api.auth'] 读取的 config/api.php  'auth' => ['jwt' => 'Dingo\Api\Auth\Provider\JWT'], 所以 在 Kernel.php 找不到这个中间件
 |--------------------------------------------------------------
 */
    $api->group([
        'middleware' => ['apiLogs', 'checkAuth', '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(['namespace' => 'Ai'], function ($api) {
            $api->group(['prefix' => 'ai'], function ($api) {
                $api->post('submitTask', 'AiController@submitTask'); // 提交任务
                $api->get('getTaskDetail', 'AiController@getTaskDetail'); // 获取任务详情
                $api->get('downloadPdf', 'AiController@downloadPdf'); // 下载pdf
            });
        });

        $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->get('parent', 'UserController@parent'); // 用户信息
            $api->post('update', 'UserController@update'); // 更新用户信息
            $api->post('{id}/bind', 'UserController@bind'); // 绑定上级
            $api->post('applyShare', 'UserController@applyShare'); // 申请推广大使
            $api->get('myTeam', 'UserController@myTeam'); // 我的团队
            $api->get('myGiveaway', 'UserController@myGiveaway'); // 我的分佣
            $api->post('userWithdraw', 'UserController@userWithdraw'); // 用户提现
            $api->get('userWithdrawList', 'UserController@userWithdrawList'); // 提现记录
            $api->get('myShare', 'UserController@myShare'); // 我的推荐
            $api->get('myConsumeList', 'UserController@myConsumeList'); // 我的消费记录
            $api->get('myOrderList', 'UserController@myOrderList'); // 我的充值记录
            $api->get('myRoleList', 'UserController@myRoleList'); // 我的角色列表
            $api->get('getUserRqCode', 'UserController@getUserRqCode'); // 我的角色列表
            $api->post('deleteRole', 'UserController@deleteRole'); // 删除角色
            $api->post('updateRole', 'UserController@updateRole'); // 更新角色
            $api->post('addRole', 'UserController@addRole'); // 添加角色
            $api->group(['namespace' => 'User'], function ($api) {
                /* @var Dingo\Api\Routing\Router $api */
                // 观看记录相关
                $api->group(['prefix' => 'watch'], function ($api) {
                    /* @var Dingo\Api\Routing\Router $api */
                    $api->get('record', 'WatchRecordsController@lists');
                    $api->post('{id}/destroy', 'WatchRecordsController@destroy');
                    $api->get('recent', 'WatchRecordsController@recent');
                    $api->post('episode', 'WatchRecordsController@watched');
                });

                // 消费相关
                $api->group(['prefix' => 'consume'], function ($api) {
                    /* @var Dingo\Api\Routing\Router $api */
                    $api->get('record', 'ConsumeController@record');
                });

                // 充值相关
                $api->group(['prefix' => 'recharge'], function ($api) {
                    /* @var Dingo\Api\Routing\Router $api */
                    $api->get('record', 'RechargeController@record');
                    $api->post('create/order', 'RechargeController@pay');
                });

                // VIP相关
                $api->group(['prefix' => 'vip'], function ($api) {
                    /* @var Dingo\Api\Routing\Router $api */
                    $api->get('setting', 'VipController@setting');
                    $api->get('last', 'VipController@last');
                    $api->post('create/order', 'VipController@createOrder');
                });

                // 收藏相关
                $api->group(['prefix' => 'collect'], function ($api) {
                    /* @var Dingo\Api\Routing\Router $api */
                    $api->get('record', 'CollectController@record');
                    $api->post('{id}/check', 'CollectController@check');
                    $api->post('{id}/add', 'CollectController@add');
                    $api->post('{id}/destroy', 'CollectController@destroy');
                });

                // 喜欢相关
                $api->group(['prefix' => 'favorite'], function ($api) {
                    /* @var Dingo\Api\Routing\Router $api */
                    $api->post('{id}/check', 'FavoriteController@check');
                    $api->post('{id}/add', 'FavoriteController@add');
                    $api->post('{id}/destroy', 'FavoriteController@destroy');
                });

                // 签到相关
                $api->group(['prefix' => 'sign'], function ($api) {
                    /* @var Dingo\Api\Routing\Router $api */
                    $api->get('setting', 'SignController@setting');
                    $api->post('handle', 'SignController@handle');
                });

                // 用户剧集
                $api->group(['prefix' => 'episode'], function ($api) {
                    /* @var Dingo\Api\Routing\Router $api */
                    $api->get('buy/{episode}/record', 'EpisodeController@buyRecord');
                    $api->post('{episode}/{list}/buy', 'EpisodeController@buy');
                });
            });
        });

        // 相关设置
        $api->group(['prefix' => 'setting'], function ($api) {
            /* @var Dingo\Api\Routing\Router $api */
            $api->get('tabBar', 'SettingController@tabBar'); // 底部导航
            $api->get('navBar', 'SettingController@navBar'); // 首页顶部分类

            $api->get('homeColumn', 'SettingController@homeColumn'); // homeColumn
            $api->get('rechargeCombo', 'SettingController@rechargeCombo'); // 充值
            $api->get('config', 'SettingController@config'); // 相关设置
        });

        // 相关设置
        $api->group(['prefix' => 'setting'], function ($api) {
            /* @var Dingo\Api\Routing\Router $api */
            $api->get('tabBar', 'SettingController@tabBar'); // 底部导航
            $api->get('navBar', 'SettingController@navBar'); // 首页顶部分类
            $api->get('banner', 'SettingController@banner'); // banner
            $api->get('homeColumn', 'SettingController@homeColumn'); // homeColumn
            $api->get('rechargeCombo', 'SettingController@rechargeCombo'); // 充值
        });

        // 分销
        $api->group(['namespace' => 'Share', 'prefix' => 'share'], function ($api) {
            /* @var Dingo\Api\Routing\Router $api */
            $api->get('order/lists', 'OrderController@lists'); // 分销订单
            $api->get('team/lists', 'TeamController@lists'); // 分销订单
            $api->get('withdraw/lists', 'WithdrawController@lists'); // 分销订单
            $api->post('withdraw/create', 'WithdrawController@create'); // 分销订单
            $api->get('income', 'ShareController@income'); // 分销明细
            $api->get('tips', 'ShareController@tips'); // 用户需知
            $api->get('setting', 'ShareController@setting'); // 设置
            $api->post('generate/qrcode', 'ShareController@generateQrcode'); // 生成二维码
        });

        // 短剧
        $api->group(['prefix' => 'episode'], function ($api) {
            /* @var Dingo\Api\Routing\Router $api */
            $api->get('recommend', 'EpisodeController@recommend'); // 推荐
            $api->get('today/recommend', 'EpisodeController@todayRecommend'); // 今日推荐
            $api->get('news', 'EpisodeController@news'); // 最新
            $api->get('rank', 'EpisodeController@rank'); // 排行
            $api->get('trace', 'EpisodeController@trace'); // 追剧
            $api->get('list', 'EpisodeController@list'); // 列表
            $api->get('search', 'EpisodeController@search'); // 搜索
            $api->get('vip/free', 'EpisodeController@vipFree'); // banner
            $api->get('{id}/detail', 'EpisodeController@detail'); // 详情
            $api->get('/list/{listId}/buyNum', 'EpisodeController@listBuyNum'); // 详情
            $api->post('{id}/shared', 'EpisodeController@shared'); // 分享
        });
    });

    $api->get('pay/{pay_id}/query', 'PayController@query'); // 字节跳动支付
    $api->any('pay/bytedance/notify', 'PayNoticeController@bytedance'); // 字节跳动支付回调
    $api->any('pay/bytedance/settle', 'PayNoticeController@bytedanceSettle'); // 字节跳动结算回调
    $api->any('pay/kuaishou/notify', 'PayNoticeController@kuaishou'); // 快手支付回调
    $api->any('pay/kuaishou/settle', 'PayNoticeController@kuaishouSettle'); // 快手结算回调
    $api->any('pay/wechat/notify', 'PayNoticeController@wechat'); // 微信支付回调
});
