<?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::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')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//添加联系人
    Route::get('user/contactslist','UserController@contactslist');//返回当前登入的联系人列表
    Route::get('user/deupuser','UserController@deupuser');//返回当前登入的联系人列表
});

//上传图片路由
Route::group(['middleware'=>'auth:api'],function (){
    Route::post('SwooleCommand/SwooleCommand','SwooleCommandController@index');//添加图片
    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');//更新图片信息,返回逻辑图片列表

});
//设备路由
Route::group(['middleware'=>'auth:api'],function (){
    Route::get('devices/devicelist', 'DevicesController@devicelist');//设备列表
    Route::get('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')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//新增设备
    Route::match(['get','post'],'devices/physicsdelete','DevicesController@physicsdelete')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//返回设备列表和更改设备
    Route::match(['get','post'],'devices/updatedevice','DevicesController@updatedevice')->middleware('permission:' . \App\Laravue\Acl::PERMISSION_PERMISSION_MANAGE);//更新设备
    Route::get('devices/equipment','DevicesController@equipment');//获取设备监测列表
    Route::get('devices/police','DevicesController@police');//获取设备当前报警列表

});

//装维中心
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);//删除用户
});
// 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]));
});
