<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\WorkerAuthController;
use App\Http\Controllers\Api\WorkerProfileController;
use App\Http\Controllers\Api\WorkerMessageController;
use App\Http\Controllers\Api\WorkerAnnouncementController;
use App\Http\Controllers\Api\EmployerAuthController;
use App\Http\Controllers\Api\EmployerMessageController;
use App\Http\Controllers\Api\EmployerAnnouncementController;
use App\Http\Controllers\Api\EmployerProfileController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your mobile app. These
| routes are loaded by bootstrap/app.php and are automatically prefixed
| with "api/" and assigned the stateless api middleware.
|
*/

// Unprotected Worker Mobile Auth Endpoints
Route::get('/workers/config', [WorkerAuthController::class, 'config']);
Route::post('/workers/send-otp', [WorkerAuthController::class, 'sendOtp']);
Route::post('/workers/verify-otp', [WorkerAuthController::class, 'verifyOtp']);
Route::post('/workers/setup-profile', [WorkerAuthController::class, 'setupProfile']);
Route::post('/workers/register', [WorkerAuthController::class, 'register']);
Route::post('/workers/login', [WorkerAuthController::class, 'login']);

// Unprotected Employer Mobile Auth Endpoints
Route::post('/employers/register', [EmployerAuthController::class, 'register']);
Route::post('/sponsors/register', [EmployerAuthController::class, 'register']);
Route::post('/employers/verify', [EmployerAuthController::class, 'verify']);
Route::post('/sponsors/verify', [EmployerAuthController::class, 'verify']);
Route::post('/employers/payment', [EmployerAuthController::class, 'payment']);
Route::post('/sponsors/payment', [EmployerAuthController::class, 'payment']);
Route::post('/employers/password', [EmployerAuthController::class, 'password']);
Route::post('/sponsors/password', [EmployerAuthController::class, 'password']);
Route::get('/employers/plans', [EmployerAuthController::class, 'plans']);
Route::get('/sponsors/plans', [EmployerAuthController::class, 'plans']);
Route::post('/employers/login', [EmployerAuthController::class, 'login']);

// Protected Worker Mobile Endpoints (Token Authenticated via Bearer Token)
Route::middleware(['auth.worker'])->group(function () {
    // Profile Management
    Route::get('/workers/profile', [WorkerProfileController::class, 'getProfile']);
    Route::post('/workers/profile/update', [WorkerProfileController::class, 'updateProfile']);
    Route::post('/workers/profile/upload-emirates-id', [WorkerProfileController::class, 'uploadEmiratesId']);
    Route::post('/workers/go-live', [WorkerProfileController::class, 'goLive']);
    Route::post('/workers/profile/toggle-availability', [WorkerProfileController::class, 'toggleAvailability']);
    Route::post('/workers/profile/mark-hired', [WorkerProfileController::class, 'markHired']);
    
    // Job Offers Management
    Route::get('/workers/offers', [WorkerProfileController::class, 'getOffers']);
    Route::post('/workers/offers/{id}/respond', [WorkerProfileController::class, 'respondToOffer']);

    // Messaging Management
    Route::get('/workers/conversations', [WorkerMessageController::class, 'getConversations']);
    Route::get('/workers/conversations/{id}/messages', [WorkerMessageController::class, 'getMessages']);
    Route::post('/workers/conversations/{id}/messages', [WorkerMessageController::class, 'sendMessage']);

    // Announcement Management
    Route::get('/workers/announcements', [WorkerAnnouncementController::class, 'getAnnouncements']);
});

// Protected Employer Mobile Endpoints (Token Authenticated via Bearer Token)
Route::middleware(['auth.employer'])->group(function () {
    // Profile Management
    Route::get('/employers/profile', [EmployerProfileController::class, 'getProfile']);
    Route::post('/employers/profile/update', [EmployerProfileController::class, 'updateProfile']);

    // Messaging Management
    Route::get('/employers/conversations', [EmployerMessageController::class, 'getConversations']);
    Route::get('/employers/conversations/{id}/messages', [EmployerMessageController::class, 'getMessages']);
    Route::post('/employers/conversations/{id}/messages', [EmployerMessageController::class, 'sendMessage']);
    Route::post('/employers/conversations/start', [EmployerMessageController::class, 'startConversation']);

    // Announcement Management
    Route::get('/employers/announcements', [EmployerAnnouncementController::class, 'getAnnouncements']);
    Route::post('/employers/announcements', [EmployerAnnouncementController::class, 'createAnnouncement']);
    Route::delete('/employers/announcements/{id}', [EmployerAnnouncementController::class, 'deleteAnnouncement']);
});
