<?php

use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\ChatController;
use App\Http\Controllers\Api\CompanyController;
use App\Http\Controllers\Api\ForumController;
use App\Http\Controllers\Api\ProductController;
use App\Http\Controllers\Api\ReportController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

/**
 * Auth APIs
*/
Route::prefix('auth')->group(function() {
    Route::post('login', [AuthController::class, 'login']);
    Route::post('register', [AuthController::class, 'register']);
    Route::post('social-login', [AuthController::class, 'socialLogin']);
    Route::post('forgot-password', [AuthController::class, 'forgotPassword']);
    Route::post('verify-token', [AuthController::class, 'verifyToken']);
    Route::post('set-password', [AuthController::class, 'setPassword']);
    Route::post('resend-otp-token', [AuthController::class, 'resendOtpToken']);
    Route::post('test-notification', [AuthController::class, 'testNotification']);


    Route::group(['middleware' => ['auth:sanctum']], function () {
        Route::post('register-company', [AuthController::class, 'registerCompnay']);
        Route::post('reset-password', [AuthController::class, 'resetPassword']);
        Route::post('update-fcm-token', [AuthController::class, 'updateFcmToken']);
        Route::post('update-notification-status', [AuthController::class, 'updateNotificationStatus']);
        Route::post('change-password', [AuthController::class, 'changePassword']);
        Route::post('logout', [AuthController::class, 'logout']);
        Route::post('update-profile', [AuthController::class, 'updateProfile']);
        Route::post('update-company-profile', [AuthController::class, 'updateCompanyProfile']);
        Route::delete('delete-account', [AuthController::class, 'deleteAccount']);
        Route::post('update-online-status', [AuthController::class, 'updateOnlineStatus']);
    });
    Route::get('unauthenticated', [AuthController::class, 'unauthenticatedUser'])->name('unauthenticated');
});

Route::middleware(['optional.sanctum'])->group(function () {

    Route::post('/report', [ReportController::class, 'store']);

    Route::get('constants', [ProductController::class, 'constants']);
    Route::get('filter-properties', [ProductController::class, 'filterProperties']);
    Route::get('sendMessageNotification',[ChatController::class,'sendMessageNotification']);

    Route::get('dashboard', [ProductController::class, 'dashboard']);
    Route::get('categories', [ProductController::class, 'categories']);
    Route::get('products', [ProductController::class, 'index']);
    Route::get('products/detail/{id}', [ProductController::class, 'productDetail']);
    Route::get('companies', [CompanyController::class, 'allCompanies']);
    Route::get('company/details/{id}', [CompanyController::class, 'details']);

    Route::get('/jobs', [CompanyController::class, 'jobs']);
    Route::get('jobs/applicants', [CompanyController::class, 'jobApplicants']);
    Route::get('jobs/detail/{id}', [CompanyController::class, 'jobDetail']);

    Route::get('/forums', [ForumController::class, 'index']);
    Route::get('search-results', [CompanyController::class, 'searchResults']);
});

Route::middleware(['auth:sanctum'])->group(function() {

    // Route::get('dashboard', [ProductController::class, 'dashboard']);
    // Route::get('categories', [ProductController::class, 'categories']);
    // Route::get('products', [ProductController::class, 'index']);
    // Route::get('products/detail/{id}', [ProductController::class, 'productDetail']);
    // Route::get('companies', [CompanyController::class, 'allCompanies']);
    // Route::get('company/details', [CompanyController::class, 'details']);
    Route::post('products/add', [ProductController::class, 'addProduct']);
    Route::post('products/edit/{id}', [ProductController::class, 'editProduct']);
    Route::post('products/update-status', [ProductController::class, 'updateStatus']);
    Route::delete('products/delete/{id}', [ProductController::class, 'deleteProduct']);
    Route::delete('products/delete-image/{id}', [ProductController::class, 'deleteProductImage']);

    Route::prefix('jobs')->group(function(){
        Route::get('/', [CompanyController::class, 'jobs']);
        Route::post('create', [CompanyController::class, 'createJob']);
        Route::post('/apply', [CompanyController::class, 'applyJob']);
        Route::post('/edit/{id}', [CompanyController::class, 'editJob']);
        Route::delete('/delete/{id}', [CompanyController::class, 'deleteJob']);
        Route::post('/update-status', [CompanyController::class, 'updateJobStatus']);
        // Route::get('/applicants', [CompanyController::class, 'jobApplicants']);
        // Route::get('/detail/{id}', [CompanyController::class, 'jobDetail']);
    });

    Route::prefix('forums')->controller(ForumController::class)->group(function(){
        // Route::get('/', 'index');
        Route::post('/create', 'addForum');
        Route::post('/edit/{id}', 'editForum');
        Route::delete('/delete/{id}', 'deleteForum');
        Route::post('/like', 'like');
        Route::post('/comment', 'comment');
        Route::delete('/delete-file/{id}', 'deleteForumFile');
        Route::post('/update-status', 'updateStatus');
    });

    Route::controller(ChatController::class)->group(function () {
        Route::get('get-chats', 'getChats');
        Route::get('get-messages', 'getChatMessages');
        Route::post('chat-file-upload', 'chatFileUpload');
        Route::get('get-available-users', 'availableUsers');
        Route::delete('delete-chat', 'deleteChat');
    });

    Route::post('save-item', [CompanyController::class, 'saveItem']);
    Route::get('saved-items', [CompanyController::class, 'savedItems']);
    Route::get('notifications', [CompanyController::class, 'getNotifications']);
    Route::post('mark-read-notification', [CompanyController::class, 'markNotificationRead']);
    // Route::get('search-results', [CompanyController::class, 'searchResults']);
    Route::get('get-ureads', [CompanyController::class, 'getUnreads']);

    Route::post('save-click-view', [CompanyController::class, 'saveClickAndView']);


});


