<?php

use Illuminate\Http\Request;
use \App\Laravue\Faker;
use \App\Laravue\JsonResponse;

/*
|--------------------------------------------------------------------------
| 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::post('auth/login', 'AuthController@login');
Route::post('auth/userslogin', 'AuthController@userslogin');//用户登入接口
Route::post('huinapphome/isemail','UinappHomeController@isemail');//邮箱验证
Route::post('huinapphome/ispassword','UinappHomeController@ispassword');//密码更改
Route::post('huinapphome/mails','UinappHomeController@mails');//邮箱验证码发送
Route::group(['middleware' => 'auth:api'], function () {
    Route::get('auth/user', 'AuthController@user');
    Route::post('auth/logout', 'AuthController@logout');
    Route::apiResource('users', 'UserController')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_USER_MANAGE);
    Route::get('users/{user}/permissions', 'UserController@permissions')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);
    Route::put('users/{user}/permissions', 'UserController@updatePermissions')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);
    Route::apiResource('roles', 'RoleController')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);
    Route::get('roles/{role}/permissions', 'RoleController@permissions')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);
    Route::apiResource('permissions', 'PermissionController')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);

    Route::get('wxuser/wxlist', 'WxuserController@wxlist');//微信用户列表
    Route::post('wxuser/seek','WxuserController@seek');//微信搜索
    Route::get('user/HUserList', 'UserController@HUserList');//用户列表
    Route::post('user/userSeek', 'UserController@userSeek');//用户搜索

    Route::post('user/addUser', 'UserController@addUser')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//新增用户
    Route::post('user/deleteuser','UserController@deleteuser')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//删除用户
    Route::match(['get','post'],'user/Upuser','UserController@Upuser')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//更新用户
    Route::match(['get','post'],'user/areachina','UserController@areachina')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//获取地址列表
    Route::post('user/addcontactsuser','UserController@addcontactsuser');//添加联系人
    Route::get('user/contactslist','UserController@contactslist');//返回当前登入的联系人列表
    Route::get('user/UpPaperBasket/{id}','UserController@UpPaperBasket');//更新废纸篓和禁用用户
    Route::get('user/UpuserForbidden/{id}','UserController@UpuserForbidden');//禁用此用户
    Route::get('user/paperBasket','UserController@paperBasket');//返回废纸篓数量
    Route::get('user/paperBasketList','UserController@paperBasketList');//返回废纸篓和用户状态
    Route::get('user/userLocation','UserController@userLocation');//返回用户安装位置
    Route::get('user/textcountuser','UserController@textcountuser');//用户测试接口
});

//上传图片路由
Route::group(['middleware'=>'auth:api'],function (){
    Route::post('upload_img/uploadingimg','UploadimgController@uploadingimg')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//添加图片
    Route::get('userimglist/userimglist','UploadimgController@userlist');//图片列表
    Route::get('userimgdetele/userimgdetele','UploadimgController@userimgdetele');//删除图片
    Route::match(['get','post'],'updateimg/updateimg','UploadimgController@updateimg');//更新图片信息,返回逻辑图片列表

});

//swoole
Route::group(['middleware'=>'auth:api'],function (){
    Route::post('SwooleCommand/SwooleCommand','SwooleCommandController@index');
});


//用户路由
Route::group(['middleware'=>'auth:api'],function (){
});

//首页路由
Route::group(['middleware'=>'auth:api'],function (){
    Route::get('homepagecount/homepagecount','HomepageController@homepagecount');
    Route::get('homepagecount/devicemonthcount','HomepageController@devicemonthcount');
    Route::get('homepagecount/timeline','HomepageController@gettimeline');
    Route::get('homepagecount/Project_statistics','HomepageController@Project_statistics');
    Route::get('homepagecount/UserStatistics','HomepageController@UserStatistics');
    Route::get('homepagecount/userdevicemonthcount','HomepageController@userdevicemonthcount');

});

//设备路由
Route::group(['middleware'=>'auth:api'],function (){
    Route::get('devices/devicelist', 'DevicesController@devicelist');//设备列表
    Route::post('devices/userdevicelist', 'DevicesController@userdevicelist');//用户设备列表
    Route::get('devices/deviceDataInfo/{id}', 'DevicesController@deviceDataInfo');//设备详情
    Route::post('devices/deviceDataSearch', 'DevicesController@deviceDataSearch');//设备搜索列表
    Route::get('devices/devicetype','DevicesController@devicetype');//设备类型
    Route::post('devices/deletedecice','DevicesController@deletedecice')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//删除设备
    Route::post('devices/adddevice','DevicesController@adddevice');//新增设备
    Route::match(['get','post'],'devices/physicsdelete','DevicesController@physicsdelete')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//返回设备列表和更改设备
    Route::match(['get','post'],'devices/updatedevice','DevicesController@updatedevice');//更新设备
    Route::get('devices/equipment','DevicesController@equipment');//获取设备监测列表
    Route::get('devices/police','DevicesController@police');//获取设备当前报警列表
    Route::get('devices/deviceBasket','DevicesController@deviceBasket');//获取设备废纸篓数量
    Route::get('devices/deviceDelete','DevicesController@deviceDelete');//禁用设备和丢弃废纸篓
    Route::get('devices/UpPaperBasket/{id}','DevicesController@UpPaperBasket');//更新废纸篓和禁用用户
    Route::get('devices/deviceBasketList','DevicesController@deviceBasketList');//返回禁用设备和废纸篓设备
    Route::get('devices/addClassify/{data}','DevicesController@addClassify');//添加分类
    Route::post('devices/updateClassify','DevicesController@updateClassify');//删除分类
    Route::get('devices/delteClassify/{id}','DevicesController@delteClassify');//删除分类
    Route::post('devices/detedevice','DevicesController@detedevice');//查看历史数据
    Route::get('devices/addUserDevice','DevicesController@addUserDevice');//返回正常用户
    Route::get('devices/control','DevicesController@control');//返回消防监测
    Route::get('devices/deviceLocation','DevicesController@deviceLocation');//返回设备安装位置
    Route::get('devices/device_info/{id}','DevicesController@device_info');//返回设备地图详情信息
    Route::get('devices/devicepolice','DevicesController@devicepolice');//设备消警
    Route::get('devices/devicepoliceinfo','DevicesController@devicepoliceinfo');//设备报警弹窗详情
    // 设备型号
    Route::get('device/models', 'ModelNumberController@index');
    Route::post('device/models', 'ModelNumberController@store');
    Route::put('device/models/{id}', 'ModelNumberController@update');
    Route::delete('device/models/{id}', 'ModelNumberController@destroy');
});

//装维中心
Route::group(['middleware'=>'auth:api'],function (){
    Route::get('installer/installerlist','InstallerController@installerlist');//装维人员列表
    Route::post('installer/addinstaller','InstallerController@addinstaller')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//添加新的装维人员
    Route::match(['get','post'],'installer/updateinstaller','InstallerController@updateinstaller')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//返回设备列表和更改设备
    Route::get('installer/deleteinstaller','InstallerController@deleteinstaller')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//删除用户
    Route::post('installer/seekInstaller','InstallerController@seekInstaller')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//用户搜索
    Route::get('installer/normalinstaller/{id}','InstallerController@normalinstaller');//回复状态
});

//uinapp 接口
Route::group(['middleware'=>'auth:api'],function (){
    Route::get('huinapphome/devicedatainfo/{id}','UinappHomeController@devicedatainfo');//设备详情
    Route::post('huinapphome/imitation','UinappHomeController@imitation');//模糊查询
    Route::post('huinapphome/setseachdata','UinappHomeController@setseachdata');//指定查询
    Route::get('huinapphome/devicetype','UinappHomeController@devicetype');//测试添加页面选择数组数据
});
// Fake APIs
Route::get('/table/list', function () {
    $rowsNumber = mt_rand(20, 30);
    $data = [];
    for ($rowIndex = 0; $rowIndex < $rowsNumber; $rowIndex++) {
        $row = [
            'author' => Faker::randomString(mt_rand(5, 10)),
            'display_time' => Faker::randomDateTime()->format('Y-m-d H:i:s'),
            'id' => mt_rand(100000, 100000000),
            'pageviews' => mt_rand(100, 10000),
            'status' => Faker::randomInArray(['deleted', 'published', 'draft']),
            'title' => Faker::randomString(mt_rand(20, 50)),
        ];

        $data[] = $row;
    }

    return response()->json(new JsonResponse(['items' => $data]));
});

Route::get('/orders', function () {
    $rowsNumber = 8;
    $data = [];
    for ($rowIndex = 0; $rowIndex < $rowsNumber; $rowIndex++) {
        $row = [
            'order_no' => 'LARAVUE' . mt_rand(1000000, 9999999),
            'price' => mt_rand(10000, 999999),
            'status' => Faker::randomInArray(['success', 'pending']),
        ];

        $data[] = $row;
    }

    return response()->json(new JsonResponse(['items' => $data]));
});

Route::get('/articles', function () {
    $rowsNumber = 10;
    $data = [];
    for ($rowIndex = 0; $rowIndex < $rowsNumber; $rowIndex++) {
        $row = [
            'id' => mt_rand(100, 10000),
            'display_time' => Faker::randomDateTime()->format('Y-m-d H:i:s'),
            'title' => Faker::randomString(mt_rand(20, 50)),
            'author' => Faker::randomString(mt_rand(5, 10)),
            'comment_disabled' => Faker::randomBoolean(),
            'content' => Faker::randomString(mt_rand(100, 300)),
            'content_short' => Faker::randomString(mt_rand(30, 50)),
            'status' => Faker::randomInArray(['deleted', 'published', 'draft']),
            'forecast' => mt_rand(100, 9999) / 100,
            'image_uri' => 'https://via.placeholder.com/400x300',
            'importance' => mt_rand(1, 3),
            'pageviews' => mt_rand(10000, 999999),
            'reviewer' => Faker::randomString(mt_rand(5, 10)),
            'timestamp' => Faker::randomDateTime()->getTimestamp(),
            'type' => Faker::randomInArray(['US', 'VI', 'JA']),

        ];

        $data[] = $row;
    }

    return response()->json(new JsonResponse(['items' => $data, 'total' => mt_rand(1000, 10000)]));
});

Route::get('articles/{id}', function ($id) {
    $article = [
        'id' => $id,
        'display_time' => Faker::randomDateTime()->format('Y-m-d H:i:s'),
        'title' => Faker::randomString(mt_rand(20, 50)),
        'author' => Faker::randomString(mt_rand(5, 10)),
        'comment_disabled' => Faker::randomBoolean(),
        'content' => Faker::randomString(mt_rand(100, 300)),
        'content_short' => Faker::randomString(mt_rand(30, 50)),
        'status' => Faker::randomInArray(['deleted', 'published', 'draft']),
        'forecast' => mt_rand(100, 9999) / 100,
        'image_uri' => 'https://via.placeholder.com/400x300',
        'importance' => mt_rand(1, 3),
        'pageviews' => mt_rand(10000, 999999),
        'reviewer' => Faker::randomString(mt_rand(5, 10)),
        'timestamp' => Faker::randomDateTime()->getTimestamp(),
        'type' => Faker::randomInArray(['US', 'VI', 'JA']),

    ];

    return response()->json(new JsonResponse($article));
});

Route::get('articles/{id}/pageviews', function ($id) {
    $pageviews = [
        'PC' => mt_rand(10000, 999999),
        'Mobile' => mt_rand(10000, 999999),
        'iOS' => mt_rand(10000, 999999),
        'android' => mt_rand(10000, 999999),
    ];
    $data = [];
    foreach ($pageviews as $device => $pageview) {
        $data[] = [
            'key' => $device,
            'pv' => $pageview,
        ];
    }

    return response()->json(new JsonResponse(['pvData' => $data]));
});
