<?php

use Illuminate\Support\Facades\Route;
use Lucent\Http\Controller\AccountController;
use Lucent\Http\Controller\AuthController;
use Lucent\Http\Controller\BuildController;
use Lucent\Http\Controller\FileController;
use Lucent\Http\Controller\HomeController;
use Lucent\Http\Controller\MemberController;
use Lucent\Http\Controller\RecordController;
use Lucent\Http\Controller\RevisionController;


Route::group([
    'middleware' => ['web'],
    'prefix' => "lucent"
], function () {

    Route::middleware(['lucent.guest'])->group(function () {
        Route::get('/', [AuthController::class, 'login']);
        Route::get('/register', [AuthController::class, 'register']);
        Route::post('/register', [AuthController::class, 'postRegister']);
        Route::get('/login', [AuthController::class, 'login']);
        Route::post('/login', [AuthController::class, 'postLogin']);
        Route::get('/verify', [AuthController::class, 'verify']);
        Route::post('/verify', [AuthController::class, 'postVerify']);

    });

    Route::middleware('lucent.auth')->group(function () {
        Route::get('/logout', [AuthController::class, 'logout']);
        Route::get('/profile', [AccountController::class, 'profile']);
        Route::post('/account/update-name', [AccountController::class, 'updateName']);
        Route::post('/account/update-email', [AccountController::class, 'updateEmail']);
        Route::get('/build-report', [BuildController::class, 'report']);
        Route::get('/build-report-source', [BuildController::class, 'reportSource']);
        Route::post('/build', [BuildController::class, 'build']);
    });


    Route::middleware(["lucent.auth"])->group(function () {
        Route::get('/members/', [MemberController::class, 'index']);
        Route::post('/members/invite', [MemberController::class, 'invite']);
        Route::post('/members/update', [MemberController::class, 'update']);
    });


    Route::middleware(["lucent.auth"])->prefix("/records")->group(function () {

        Route::get('/new', [RecordController::class, 'new']);
        Route::get('/newInline', [RecordController::class, 'newInline']);
        Route::get('/suggestions', [RecordController::class, 'suggestions']);
        Route::get('/{rid}', [RecordController::class, 'edit']);
        Route::post('/clone/{rid}', [RecordController::class, 'clone']);
//        Route::get('/editInline/{rid}', [RecordController::class, 'editInline']);
        Route::get('/{rid}/parents', [RecordController::class, 'parents']);
        Route::post('/', [RecordController::class, 'save']);
        Route::post('/status/{status}', [RecordController::class, 'status']);
        Route::post('/delete', [RecordController::class, 'delete']);
        Route::post('/{rid}/rollback/{version}', [RecordController::class, 'rollback']);
    });

    Route::middleware(["lucent.auth"])->group(function () {
        Route::get('/records/{rid}/revisions', [RevisionController::class, 'index']);

    });

    Route::middleware(["lucent.auth"])->group(function () {
        Route::get('/', [HomeController::class, 'home']);
        Route::get('/home/records', [HomeController::class, 'records']);
    });

    Route::middleware(["lucent.auth"])->prefix("/content")->group(function () {
        Route::get('/{schemaName}', [RecordController::class, 'index']);
        Route::get('/{schemaName}/csv', [RecordController::class, 'exportCSV']);
        Route::get('/{schemaName}/emptyTrash', [RecordController::class, 'emptyTrash']);
    });

    Route::middleware(["lucent.auth"])->group(function () {
        Route::post('/files/upload', [FileController::class, 'upload']);
        Route::get('/files/download', [FileController::class, 'download']);
    });



});

