<?php

use App\Http\Controllers\Admin\AdminController;
use App\Http\Controllers\Admin\CampaignController;
use App\Http\Controllers\Admin\CategoryController;
use App\Http\Controllers\Admin\ChatController;
use App\Http\Controllers\Admin\ExportController;
use App\Http\Controllers\Admin\ForumController;
use App\Http\Controllers\Admin\ImportController;
use App\Http\Controllers\Admin\JobsController;
use App\Http\Controllers\Admin\ProductController;
use App\Http\Controllers\Admin\PromotionController;
use App\Http\Controllers\Admin\ReportController;
use App\Http\Controllers\Admin\UserController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

use App\Http\Controllers\Admin\PreClaimController;

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

Route::get('admin', function () {
    return redirect(route('admin.login'));
});
Route::match(['get', 'post'],'admin/login', [AdminController::class, 'login'])->name('admin.login');
Route::get('logout', function (){
    Auth::logout();
    return redirect(route('admin.login'));
});

Route::prefix('admin')->name('admin.')->middleware('admin')->group(function (){
    Route::get('/dashboard', [AdminController::class, 'dashboard'])->name('dashboard');
    Route::match(['get', 'post'], '/setting', [AdminController::class, 'setting'])->name('setting');
    Route::get('/change-password', [AdminController::class, 'changePassword'])->name('changePassword');
    Route::post('/update-admin-password', [AdminController::class, 'updateAdminPassword'])->name('updateAdminPassword');
    Route::patch('/fcm-token', [AdminController::class, 'updateToken'])->name('fcmToken');


    Route::get('categories', [CategoryController::class, 'index'])->name('categories');
    Route::post('add-category', [CategoryController::class, 'add'])->name('addCategory');
    Route::post('edit-category/{id}', [CategoryController::class, 'edit'])->name('editCategory');

    Route::get('promotions', [PromotionController::class, 'index'])->name('promotions');
    Route::post('add-promotion', [PromotionController::class, 'add'])->name('addpromotion');
    Route::post('edit-promotion/{id}', [PromotionController::class, 'edit'])->name('editPromotion');

    Route::get('users', [UserController::class, 'index'])->name('users');
    Route::get('companies', [UserController::class, 'companies'])->name('companies');
    Route::get('users/detail/{id}', [UserController::class, 'detail'])->name('userDetail');
    Route::match(['get', 'post'], 'users/edit/{id}', [UserController::class, 'edit'])->name('editUser');
    Route::get('companies/detail/{id}', [UserController::class, 'detail'])->name('companyDetail');
    Route::get('export-users', [ExportController::class, 'exportUsers'])->name('exportUsers');

    Route::prefix('products')->controller(ProductController::class)->group(function(){
        Route::get('/', 'index')->name('products');
        Route::get('detail/{id}', 'detail')->name('productDetail');
        Route::match(['get', 'post'], 'create', 'create')->name('createProduct');
        Route::match(['get', 'post'], 'edit/{id}', 'edit')->name('editProduct');
        Route::get('attributes', 'productAttributes')->name('productAttributes');
    });

    Route::prefix('jobs')->controller(JobsController::class)->group(function(){
        Route::get('/', 'index')->name('jobs');
        Route::get('detail/{id}', 'detail')->name('jobDetail');
        Route::match(['get', 'post'], 'create', 'create')->name('createJob');
        Route::match(['get', 'post'], 'edit/{id}', 'edit')->name('editJob');
    });

    Route::prefix('forums')->controller(ForumController::class)->group(function(){
        Route::get('/', 'index')->name('forums');
        Route::get('detail/{id}', 'detail')->name('forumDetail');
        Route::match(['get', 'post'], 'create', 'create')->name('createForum');
        Route::match(['get', 'post'], 'edit/{id}', 'edit')->name('editForum');
    });

    Route::prefix('chat')->controller(ChatController::class)->group(function(){
        Route::get('/', 'index')->name('chat');
        Route::get('/detail/{id}', 'detail')->name('chatDetail');
    });

    Route::prefix('reports')->controller(ReportController::class)->group(function(){
        Route::get('/products', 'products')->name('reports.products');
        Route::get('/jobs', 'jobs')->name('reports.jobs');
        Route::get('/forums', 'forums')->name('reports.forums');
        Route::get('/chat-detail/{id}', 'chatDetail')->name('reports.chatDetail');
    });

    Route::prefix('import')->controller(ImportController::class)->group(function(){
        Route::post('/products', 'importProducts')->name('importProducts');
        Route::post('/products-upload', 'importProductsGeneral')->name('importProductsGeneral');
    });

    Route::get('email-templates', [AdminController::class, 'emailTemplates'])->name('emailTemplates');
    Route::get('email-templates/{id}', [AdminController::class, 'viewEmailTemplates'])->name('viewEmailTemplates');
    Route::post('email-templates/edit/{id}', [AdminController::class, 'editEmailTemplate'])->name('editEmailTemplate');

    Route::get('countries', [AdminController::class, 'countries'])->name('countries');

    Route::get('campaigns', [CampaignController::class, 'index'])->name('campaigns');
    Route::get('campaigns/detail/{id}', [CampaignController::class, 'campaignDetail'])->name('campaignDetail');


    //oddev001
    Route::prefix('pre-claim')->controller(PreClaimController::class)->group(function(){
        Route::get('/', 'index')->name('preclaim');
        Route::post('/import-pre-claim', 'import')->name('import-pre-claim');
        Route::get('/pre-claim-data/{batch}', 'data')->name('preclaim-data');
    });
    //oddev001
});
