<?php

use App\Http\Controllers\Studio\PriceRequestController;
use App\Livewire\Studio\Catalog\Bottle\Audit as BottleAudit;
use App\Livewire\Studio\Catalog\Bottle\Create as BottleCreate;
use App\Livewire\Studio\Catalog\Bottle\Edit as BottleEdit;
use App\Livewire\Studio\Catalog\Bottle\Index as BottleIndex;
use App\Livewire\Studio\Catalog\Brand as BrandComponent;
use App\Livewire\Studio\Catalog\Category as CategoryComponent;
use App\Livewire\Studio\Catalog\Perfume\Audit as PerfumeAudit;
use App\Livewire\Studio\Catalog\Perfume\Create as PerfumeCreate;
use App\Livewire\Studio\Catalog\Perfume\Edit as PerfumeEdit;
use App\Livewire\Studio\Catalog\Perfume\Index as PerfumeIndex;
use App\Livewire\Studio\Catalog\Product\Audit as ProductAudit;
use App\Livewire\Studio\Catalog\Product\Create as ProductCreate;
use App\Livewire\Studio\Catalog\Product\Edit as ProductEdit;
use App\Livewire\Studio\Catalog\Product\Index as ProductIndex;
use App\Livewire\Studio\Dashboard\Overview as OverviewComponent;
use App\Livewire\Studio\Feature\ChooseUs as ChooseUsComponent;
use App\Livewire\Studio\Feature\PerfumeFeature as PerfumeFeatureComponent;
use App\Livewire\Studio\Finance\Expense as ExpenseComponent;
use App\Livewire\Studio\Finance\Payroll as PayrollComponent;
use App\Livewire\Studio\Loyalty\Customer as CustomerComponent;
use App\Livewire\Studio\Loyalty\Tier as TierComponent;
use App\Livewire\Studio\Loyalty\Voucher\Create as VoucherCreate;
use App\Livewire\Studio\Loyalty\Voucher\Edit as VoucherEdit;
use App\Livewire\Studio\Loyalty\Voucher\Index as VoucherIndex;
use App\Livewire\Studio\Manage\Article\Create as ArticleCreate;
use App\Livewire\Studio\Manage\Article\Edit as ArticleEdit;
use App\Livewire\Studio\Manage\Article\Index as ArticleIndex;
use App\Livewire\Studio\Manage\Faq as FaqComponent;
use App\Livewire\Studio\Manage\Order\Create as OrderCreate;
use App\Livewire\Studio\Manage\Order\Index as OrderIndex;
use App\Livewire\Studio\Manage\Order\Show as OrderShow;
use App\Livewire\Studio\Manage\Purchase\Create as PurchaseCreate;
use App\Livewire\Studio\Manage\Purchase\Index as PurchaseIndex;
use App\Livewire\Studio\Master\Formula as FormulaComponent;
use App\Livewire\Studio\Master\Outlet\Create as OutletCreate;
use App\Livewire\Studio\Master\Outlet\Edit as OutletEdit;
use App\Livewire\Studio\Master\Outlet\Index as OutletIndex;
use App\Livewire\Studio\Master\User\Create as UserCreate;
use App\Livewire\Studio\Master\User\Edit as UserEdit;
use App\Livewire\Studio\Master\User\Index as UserIndex;
use App\Livewire\Studio\Setting\Account as AccountComponent;
use App\Livewire\Studio\Setting\Application as ApplicationComponent;
use App\Livewire\Studio\Setting\Password as PasswordComponent;
use App\Livewire\Studio\Setting\Profile as ProfileComponent;
use App\Livewire\Studio\Setting\Whatsapp as WhatsappComponent;
use Illuminate\Support\Facades\Route;

Route::middleware('auth')->prefix('studio')->group(function () {
    Route::prefix('setting')->name('studio.setting.')->group(function () {
        Route::get('/account/{user}', AccountComponent::class)->name('account')->middleware('can:view account');
        Route::get('/profile/{employee}', ProfileComponent::class)->name('profile')->middleware('can:view profile');
        Route::get('/password/{user}', PasswordComponent::class)->name('password')->middleware('can:view password');
    });

    Route::prefix('dashboard')->name('studio.dashboard.')->group(function () {
        Route::get('/overview', OverviewComponent::class)->name('overview')->middleware('can:view overview');
    });

    Route::prefix('master')->name('studio.master.')->group(function () {
        Route::prefix('outlets')->name('outlet.')->group(function () {
            Route::get('/', OutletIndex::class)->name('index')->middleware('can:view outlet');
            Route::get('/create', OutletCreate::class)->name('create')->middleware('can:create outlet');
            Route::get('/{outlet}/edit', OutletEdit::class)->name('edit')->middleware('can:update outlet');
            Route::delete('/{outlet}/delete', OutletCreate::class)->name('delete')->middleware('can:delete outlet');
        });

        Route::prefix('users')->name('user.')->group(function () {
            Route::get('/', UserIndex::class)->name('index')->middleware('can:view user');
            Route::get('/create', UserCreate::class)->name('create')->middleware('can:create user');
            Route::get('/{user}/edit', UserEdit::class)->name('edit')->middleware('can:update user');
            Route::delete('/{user}/delete', UserCreate::class)->name('delete')->middleware('can:delete user');
        });

        Route::prefix('formulas')->name('formula.')->group(function () {
            Route::get('/', FormulaComponent::class)->name('index')->middleware('can:view formula');
            Route::delete('/{formula}/delete', FormulaComponent::class)->name('delete')->middleware('can:delete formula');
        });
    });

    Route::prefix('loyalty')->name('studio.loyalty.')->group(function () {
        Route::prefix('tiers')->name('tier.')->group(function () {
            Route::get('/', TierComponent::class)->name('index')->middleware('can:view tier');
            Route::delete('/{tier}/delete', TierComponent::class)->name('delete')->middleware('can:delete tier');
        });

        Route::prefix('customers')->name('customer.')->group(function () {
            Route::get('/', CustomerComponent::class)->name('index')->middleware('can:view customer');
            Route::delete('/{customer}/delete', CustomerComponent::class)->name('delete')->middleware('can:delete customer');
        });

        Route::prefix('vouchers')->name('voucher.')->group(function () {
            Route::get('/', VoucherIndex::class)->name('index')->middleware('can:view voucher');
            Route::get('/create', VoucherCreate::class)->name('create')->middleware('can:create voucher');
            Route::get('/{voucher}/edit', VoucherEdit::class)->name('edit')->middleware('can:update voucher');
            Route::delete('/{voucher}/delete', VoucherCreate::class)->name('delete')->middleware('can:delete voucher');
        });
    });

    Route::prefix('catalog')->name('studio.catalog.')->group(function () {
        Route::prefix('categories')->name('category.')->group(function () {
            Route::get('/', CategoryComponent::class)->name('index')->middleware('can:view category');
            Route::delete('/{category}/delete', CategoryComponent::class)->name('delete')->middleware('can:delete category');
        });

        Route::prefix('brands')->name('brand.')->group(function () {
            Route::get('/', BrandComponent::class)->name('index')->middleware('can:view brand');
            Route::delete('/{brand}/delete', BrandComponent::class)->name('delete')->middleware('can:delete brand');
        });

        Route::prefix('perfumes')->name('perfume.')->group(function () {
            Route::get('/', PerfumeIndex::class)->name('index')->middleware('can:view perfume');
            Route::get('/create', PerfumeCreate::class)->name('create')->middleware('can:create perfume');
            Route::get('/{perfume}/edit', PerfumeEdit::class)->name('edit')->middleware('can:update perfume');
            Route::delete('/{perfume}/delete', PerfumeCreate::class)->name('delete')->middleware('can:delete perfume');
            Route::get('/{outlet}/{perfume}/audit', PerfumeAudit::class)->name('audit')->middleware('can:audit perfume');
        });

        Route::prefix('products')->name('product.')->group(function () {
            Route::get('/', ProductIndex::class)->name('index')->middleware('can:view product');
            Route::get('/create', ProductCreate::class)->name('create')->middleware('can:create product');
            Route::get('/{product}/edit', ProductEdit::class)->name('edit')->middleware('can:update product');
            Route::delete('/{product}/delete', ProductCreate::class)->name('delete')->middleware('can:delete product');
            Route::get('/{outlet}/{product}/audit', ProductAudit::class)->name('audit')->middleware('can:audit product');
        });

        Route::prefix('bottles')->name('bottle.')->group(function () {
            Route::get('/', BottleIndex::class)->name('index')->middleware('can:view bottle');
            Route::get('/create', BottleCreate::class)->name('create')->middleware('can:create bottle');
            Route::get('/{bottle}/edit', BottleEdit::class)->name('edit')->middleware('can:update bottle');
            Route::delete('/{bottle}/delete', BottleCreate::class)->name('delete')->middleware('can:delete bottle');
            Route::get('/{outlet}/{bottle}/audit', BottleAudit::class)->name('audit')->middleware('can:audit bottle');
        });
    });

    Route::prefix('finance')->name('studio.finance.')->group(function () {
        Route::prefix('expenses')->name('expense.')->group(function () {
            Route::get('/', ExpenseComponent::class)->name('index')->middleware('can:view expense');
            Route::delete('/{expense}/delete', ExpenseComponent::class)->name('delete')->middleware('can:delete expense');
        });
    });

    Route::prefix('finance')->name('studio.finance.')->group(function () {
        Route::prefix('payrolls')->name('payroll.')->group(function () {
            Route::get('/', PayrollComponent::class)->name('index')->middleware('can:view payroll');
            Route::delete('/{payroll}/delete', PayrollComponent::class)->name('delete')->middleware('can:delete payroll');
        });
    });

    Route::prefix('manage')->name('studio.manage.')->group(function () {
        Route::prefix('orders')->name('order.')->group(function () {
            Route::get('/', OrderIndex::class)->name('index')->middleware('can:view order');
            Route::get('/create', OrderCreate::class)->name('create')->middleware('can:create order');
            Route::get('/{order}/show', OrderShow::class)->name('show')->middleware('can:show order');
            Route::delete('/{order}/delete', OrderCreate::class)->name('delete')->middleware('can:delete order');
        });

        Route::prefix('purchases')->name('purchase.')->group(function () {
            Route::get('/', PurchaseIndex::class)->name('index')->middleware('can:view purchase');
            Route::get('/create', PurchaseCreate::class)->name('create')->middleware('can:create purchase');
            Route::delete('/{purchase}/delete', PurchaseCreate::class)->name('delete')->middleware('can:delete purchase');
        });

        Route::prefix('articles')->name('article.')->group(function () {
            Route::get('/', ArticleIndex::class)->name('index')->middleware('can:view article');
            Route::get('/create', ArticleCreate::class)->name('create')->middleware('can:create article');
            Route::get('/{article}/edit', ArticleEdit::class)->name('edit')->middleware('can:update article');
            Route::delete('/{article}/delete', ArticleCreate::class)->name('delete')->middleware('can:delete article');
        });

        Route::prefix('faqs')->name('faq.')->group(function () {
            Route::get('/', FaqComponent::class)->name('index')->middleware('can:view faq');
            Route::delete('/{faq}/delete', FaqComponent::class)->name('delete')->middleware('can:delete faq');
        });
    });

    Route::prefix('feature')->name('studio.feature.')->group(function () {
        Route::prefix('perfume-features')->name('perfume_feature.')->group(function () {
            Route::get('/', PerfumeFeatureComponent::class)->name('index')->middleware('can:view perfume feature');
            Route::delete('/{perfume_feature}/delete', PerfumeFeatureComponent::class)->name('delete')->middleware('can:delete perfume feature');
        });

        Route::prefix('choose-us')->name('choose_us.')->group(function () {
            Route::get('/', ChooseUsComponent::class)->name('index')->middleware('can:view choose us');
            Route::delete('/{choose_us}/delete', ChooseUsComponent::class)->name('delete')->middleware('can:delete choose us');
        });
    });

    Route::get('/settings/applications', ApplicationComponent::class)->name('studio.setting.application')->middleware('can:view application settings');
    Route::get('/settings/whatsapp', WhatsappComponent::class)->name('studio.setting.whatsapp')->middleware('can:view whatsapp settings');
});

Route::get('/price-request/{priceRequest}/approve', [PriceRequestController::class, 'approve'])
    ->name('price-request.approve')
    ->middleware('signed');
