<?php

use Illuminate\Support\Facades\Route;
use Modules\Admin\Http\Controllers\AdminController;
use Modules\Admin\Http\Middleware\AdminPolicyAuthorization;
use Modules\Admin\Http\Middleware\PostCreatePolicyAuthorization;
use Modules\Admin\Http\Middleware\GloabalAdminPathsPolicyAuthorization;

Route::get('/admin', [Modules\Admin\Http\Controllers\AdminController::class, 'index'])->name('admin.index');
Route::post('/admin/set', [Modules\Admin\Http\Controllers\AdminController::class, 'setSuperAdmin'])->name('admin.setSuperAdmin');

Route::middleware(['auth', PostCreatePolicyAuthorization::class])->group(function ()
{
    Route::post('/admin/posts/store', [Modules\Admin\Http\Controllers\AdminPostsController::class, 'store'])->name('admin.posts.store');
    Route::post('/admin/post/{post}/update', [Modules\Admin\Http\Controllers\AdminPostsController::class, 'update'])->name('admin.posts.update'); 
});

Route::middleware(['auth', AdminPolicyAuthorization::class])->group(function ()
{
    Route::middleware(['auth', AdminPolicyAuthorization::class])->group(function ()
    {
        Route::get('/admin/design', [Modules\Admin\Http\Controllers\AdminDesignController::class, 'index'])->name('admin.design');
        Route::post('/admin/design/update', [Modules\Admin\Http\Controllers\AdminDesignController::class, 'update'])->name('admin.design.update');

        Route::post('/admin/cities/{city}/update', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'update'])->name('admin.cities.update');
        Route::post('/admin/cities/create', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'create'])->name('admin.cities.create');
        Route::post('/admin/cities/{city}/delete', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'delete'])->name('admin.cities.delete');
        Route::post('/admin/cities/{city}/restore', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'restore'])->withTrashed()->name('admin.cities.restore');
        Route::get('/admin/complexes/{complex}/edit', [Modules\Admin\Http\Controllers\AdminComplexesController::class, 'edit'])->name('admin.complexes.edit');
        Route::post('/admin/complexes/create', [Modules\Admin\Http\Controllers\AdminComplexesController::class, 'create'])->name('admin.complexes.create');
        Route::post('/admin/complexes/{complex}/delete', [Modules\Admin\Http\Controllers\AdminComplexesController::class, 'delete'])->name('admin.complexes.delete');
        Route::post('/admin/complexes/{complex}/update', [Modules\Admin\Http\Controllers\AdminComplexesController::class, 'update'])->withTrashed()->name('admin.complexes.update');
        Route::post('/admin/complexes/{complex}/restore', [Modules\Admin\Http\Controllers\AdminComplexesController::class, 'restore'])->withTrashed()->name('admin.complexes.restore');
        Route::get('/admin/bitrix/webhooks', [Modules\Admin\Http\Controllers\AdminBitrixWebhooksController::class, 'index'])->name('admin.bitrix.webhooks');
        Route::post('/admin/bitrix/webhooks', [Modules\Admin\Http\Controllers\AdminBitrixWebhooksController::class, 'create'])->name('admin.bitrix.webhooks.create');
    });

    Route::get('/admin/users', [Modules\Admin\Http\Controllers\AdminUsersController::class, 'index'])->name('admin.users');
    Route::post('/admin/users/create', [Modules\Admin\Http\Controllers\AdminUsersController::class, 'store'])->name('admin.users.create');
    Route::get('/admin/users/{user}/edit', [Modules\Admin\Http\Controllers\AdminUsersController::class, 'edit'])->name('admin.users.edit');
    Route::post('/admin/users/{user}/update', [Modules\Admin\Http\Controllers\AdminUsersController::class, 'update'])->name('admin.users.update');
    Route::post('/admin/users/{user}/delete', [Modules\Admin\Http\Controllers\AdminUsersController::class, 'delete'])->name('admin.users.delete');

    Route::post('/admin/user-role/{userRole}/delete', [Modules\Admin\Http\Controllers\AdminUsersController::class, 'deleteUserRole'])->name('admin.users.role.delete');
    Route::get('/admin/companies', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'index'])->name('admin.companies');
    Route::get('/admin/companies/{company}/edit', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'edit'])->name('admin.companies.edit')->withTrashed();
    Route::post('/admin/companies/{company}/update', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'update'])->name('admin.companies.update');
    Route::post('/admin/companies/{company}/delete', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'delete'])->name('admin.companies.delete')->withTrashed();
    Route::post('/admin/companies/{company}/restore', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'restore'])->name('admin.companies.restore')->withTrashed();
    Route::post('/admin/companies/admins/{companyAdmin}/delete', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'deleteAdmin'])->name('admin.companies.admins.delete');
    Route::post('/admin/companies/agents/{agent}/delete', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'deleteAgent'])->name('admin.companies.agents.delete');
    
    Route::get('/admin/cities', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'index'])->name('admin.cities');

    Route::get('/admin/cities/managers', [Modules\Admin\Http\Controllers\AdminCityManagersController::class, 'index'])->name('admin.cities.managers');
    Route::post('/admin/cities/managers/create', [Modules\Admin\Http\Controllers\AdminCityManagersController::class, 'create'])->name('admin.cities.managers.create');
    Route::post('/admin/cities/managers/{manager}/delete', [Modules\Admin\Http\Controllers\AdminCityManagersController::class, 'delete'])->name('admin.cities.managers.delete');
    Route::get('/admin/complexes', [Modules\Admin\Http\Controllers\AdminComplexesController::class, 'index'])->name('admin.complexes');
    Route::get('/admin/payments', [Modules\Admin\Http\Controllers\AdminPaymentsController::class, 'index'])->name('admin.payments');

    Route::get('/admin/posts', [Modules\Admin\Http\Controllers\AdminPostsController::class, 'index'])->name('admin.posts');
    Route::get('/admin/posts/create', [Modules\Admin\Http\Controllers\AdminPostsController::class, 'create'])->name('admin.posts.create');
    Route::get('/admin/post/{post}/edit', [Modules\Admin\Http\Controllers\AdminPostsController::class, 'edit'])->name('admin.posts.edit');
    Route::post('/admin/post/{post}/delete', [Modules\Admin\Http\Controllers\AdminPostsController::class, 'delete'])->name('admin.posts.delete');

    Route::get('/admin/docs', [Modules\Admin\Http\Controllers\AdminDocsController::class, 'index'])->name('admin.docs');
    Route::get('/admin/docs/{document}/edit', [Modules\Admin\Http\Controllers\AdminDocsController::class, 'edit'])->name('admin.docs.edit');
    Route::post('/admin/docs/create', [Modules\Admin\Http\Controllers\AdminDocsController::class, 'store'])->name('admin.docs.create');
    Route::get('/admin/docs/{document}/edit', [Modules\Admin\Http\Controllers\AdminDocsController::class, 'edit'])->name('admin.docs.edit');
    Route::post('/admin/docs/{document}/update', [Modules\Admin\Http\Controllers\AdminDocsController::class, 'update'])->name('admin.docs.update');
    Route::post('/admin/docs/{document}/delete', [Modules\Admin\Http\Controllers\AdminDocsController::class, 'delete'])->name('admin.docs.delete');

    Route::get('/admin/bitrix', [Modules\Admin\Http\Controllers\AdminBitrixController::class, 'index'])->name('admin.bitrix');
    Route::get('/admin/bitrix/agents', [Modules\Admin\Http\Controllers\AdminBitrixController::class, 'agents'])->name('admin.bitrix.agents');
    Route::post('/admin/bitrix/agents/{agent}/set', [Modules\Admin\Http\Controllers\AdminBitrixController::class, 'setAgentId'])->name('admin.bitrix.agent.set');
    Route::get('/admin/bitrix/agents/{agent}/deals/sync', [Modules\Admin\Http\Controllers\AdminBitrixController::class, 'syncDeals'])->name('admin.bitrix.agent.deals.sync');

    Route::get('/admin/plan7', [Modules\Admin\Http\Controllers\AdminPlan7Controller::class, 'index'])->name('admin.plan7');
    Route::post('/admin/plan7/save', [Modules\Admin\Http\Controllers\AdminPlan7Controller::class, 'save'])->name('admin.plan7.save');
    
});