<?php

declare(strict_types=1);

use App\Http\Controllers\BreedController;
use App\Http\Controllers\CommentController;
use App\Http\Controllers\RatingController;
use App\Http\Controllers\Invoice\InvoiceController;
use App\Http\Controllers\Invoice\PayInvoiceController;
use App\Http\Controllers\Project\ProjectCommentController;
use App\Http\Controllers\Project\ProjectCompletionController;
use App\Http\Controllers\Project\ProjectContractController;
use App\Http\Controllers\Project\ProjectDocumentController;
use App\Http\Controllers\Project\ProjectFinanceController;
use App\Http\Controllers\Project\ProjectGalleryController;
use App\Http\Controllers\Project\ProjectGrowthController;
use App\Http\Controllers\Project\ProjectHealthController;
use App\Http\Controllers\Project\ProjectHistoryController;
use App\Http\Controllers\Project\ProjectHubController;
use App\Http\Controllers\Project\ProjectMediaController;
use App\Http\Controllers\Project\ProjectOverviewController;
use App\Http\Controllers\Project\ProjectProfitChartController;
use App\Http\Controllers\Project\ProjectRationController;
use App\Http\Controllers\Project\ProjectRatingController;
use App\Http\Controllers\Project\ProjectTransactionController;
use App\Http\Controllers\ProjectRequestController;
use App\Http\Controllers\DeviceController;
use App\Http\Controllers\PriceChartController;
use App\Http\Controllers\TwoFactorSecurityController;
use App\Http\Controllers\Wallet\BankCardController;
use App\Http\Controllers\Wallet\WalletDepositController;
use App\Http\Controllers\Wallet\WalletSummaryController;
use App\Http\Controllers\Wallet\WalletTransactionController;
use App\Http\Controllers\Wallet\WithdrawalRequestController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\DiscussionController;
use App\Http\Controllers\DiscussionMessageController;
use App\Http\Controllers\DiscussionParticipantController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\FileUploadController;
use App\Http\Controllers\ExpertController;
use App\Http\Controllers\ServiceRequestController;
use App\Http\Controllers\FaqController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\LogController;
use App\Http\Controllers\MenuController;
use App\Http\Controllers\NewsletterController;
use App\Http\Controllers\Notification\ReadNotificationController;
use App\Http\Controllers\NotificationController;
use App\Http\Controllers\OfferController;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\OtpController;
use App\Http\Controllers\PageController;
use App\Http\Controllers\Payment\PaymentController;
use App\Http\Controllers\Payment\PaymentVerifyController;
use App\Http\Controllers\Payment\VerifyPaymentController;
use App\Http\Controllers\Post\PostCategoryController;
use App\Http\Controllers\Post\PostIncreaseViewController;
use App\Http\Controllers\Post\PostLandingController;
use App\Http\Controllers\Post\PostPopularController;
use App\Http\Controllers\Post\PostPublishedController;
use App\Http\Controllers\Post\PostRelatedController;
use App\Http\Controllers\PostController;
use App\Http\Controllers\ProducerController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\ProjectController;
use App\Http\Controllers\ReportController;
use App\Http\Controllers\Report\GrowthReportController;
use App\Http\Controllers\Report\HealthReportController;
use App\Http\Controllers\Report\HealthTreatmentController;
use App\Http\Controllers\Report\RationReportController;
use App\Http\Controllers\ServiceController;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\SupportTicketController;
use App\Http\Controllers\SupportTicketReplyController;
use App\Http\Controllers\TagController;
use App\Http\Controllers\User\AuthenticateController;
use App\Http\Controllers\User\AuthProfileController;
use App\Http\Controllers\User\DashboardController;
use App\Http\Controllers\User\ForgetController;
use App\Http\Controllers\User\LoginController;
use App\Http\Controllers\User\LogoutController;
use App\Http\Controllers\User\RegisterController;
use App\Http\Controllers\User\UserTransactionsController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;

// Breed Routes (shop taxonomy)
Route::get('breeds', [BreedController::class, 'index'])->name('breeds.index');
Route::get('breeds/{breed}', [BreedController::class, 'show'])->name('breeds.show');
Route::post('breeds', [BreedController::class, 'store'])->middleware('auth:api')->name('breeds.store');
Route::match(['put', 'patch'], 'breeds/{breed}', [BreedController::class, 'update'])->middleware('auth:api')->name('breeds.update');
Route::delete('breeds/{breed}', [BreedController::class, 'destroy'])->middleware('auth:api')->name('breeds.destroy');

// Category Routes (shop taxonomy + blog)
Route::get('categories', [CategoryController::class, 'index'])->name('categories.index');
Route::get('categories/{category:slug}', [CategoryController::class, 'show'])->name('categories.show');
Route::post('categories', [CategoryController::class, 'store'])->middleware('auth:api')->name('categories.store');
Route::match(['put', 'patch'], 'categories/{category}', [CategoryController::class, 'update'])->middleware('auth:api')->name('categories.update');
Route::delete('categories/{category}', [CategoryController::class, 'destroy'])->middleware('auth:api')->name('categories.destroy');

// Home (aggregated landing page payload)
Route::get('home', HomeController::class)->name('home');

// Newsletter Routes
Route::post('newsletters', [NewsletterController::class, 'store'])->name('newsletters.store');

// Market prices chart
Route::get('prices/chart', PriceChartController::class)->name('prices.chart');

// Devices & 2FA security
Route::middleware('auth:api')->group(function (): void {
    Route::get('devices', [DeviceController::class, 'index'])->name('devices.index');
    Route::delete('devices/{device}', [DeviceController::class, 'destroy'])->name('devices.destroy');
    Route::post('devices/{device}/block', [DeviceController::class, 'block'])->name('devices.block');
    Route::post('devices/{device}/unblock', [DeviceController::class, 'unblock'])->name('devices.unblock');

    Route::get('security/two-factor', [TwoFactorSecurityController::class, 'show'])->name('security.two-factor.show');
    Route::put('security/two-factor', [TwoFactorSecurityController::class, 'update'])->name('security.two-factor.update');
});

// Contact Routes
Route::get('contacts', [ContactController::class, 'index'])->middleware('auth:api')->name('contacts.index');
Route::post('contacts', [ContactController::class, 'store'])->name('contacts.store');
Route::get('contacts/{contact}', [ContactController::class, 'show'])->middleware('auth:api')->name('contacts.show');
Route::match(['put', 'patch'], 'contacts/{contact}', [ContactController::class, 'update'])->middleware('auth:api')->name('contacts.update');
Route::delete('contacts/{contact}', [ContactController::class, 'destroy'])->middleware('auth:api')->name('contacts.destroy');

// Expert Routes (husbandry / services)
Route::get('experts', [ExpertController::class, 'index'])->name('experts.index');
Route::get('experts/{expert}', [ExpertController::class, 'show'])->name('experts.show');
Route::post('experts', [ExpertController::class, 'store'])->middleware('auth:api')->name('experts.store');
Route::match(['put', 'patch'], 'experts/{expert}', [ExpertController::class, 'update'])->middleware('auth:api')->name('experts.update');
Route::delete('experts/{expert}', [ExpertController::class, 'destroy'])->middleware('auth:api')->name('experts.destroy');

// Service / consultation requests (producer → admin → expert)
Route::middleware('auth:api')->prefix('service-requests')->group(function (): void {
    Route::get('/', [ServiceRequestController::class, 'index'])->name('service-requests.index');
    Route::post('/', [ServiceRequestController::class, 'store'])->name('service-requests.store');
    Route::get('{serviceRequest}', [ServiceRequestController::class, 'show'])->name('service-requests.show');
    Route::post('{serviceRequest}/accept', [ServiceRequestController::class, 'accept'])->name('service-requests.accept');
    Route::post('{serviceRequest}/decline', [ServiceRequestController::class, 'decline'])->name('service-requests.decline');
});

// Comment Routes (product, project, post, etc.)
Route::get('comments', [CommentController::class, 'index'])->name('comments.index');
Route::get('comments/{comment}', [CommentController::class, 'show'])->name('comments.show');
Route::post('comments', [CommentController::class, 'store'])->middleware('auth:api')->name('comments.store');
Route::match(['put', 'patch'], 'comments/{comment}', [CommentController::class, 'update'])->middleware('auth:api')->name('comments.update');
Route::delete('comments/{comment}', [CommentController::class, 'destroy'])->middleware('auth:api')->name('comments.destroy');

// Rating Routes (product, project, producer, etc.)
Route::get('ratings', [RatingController::class, 'index'])->name('ratings.index');
Route::get('ratings/{rating}', [RatingController::class, 'show'])->name('ratings.show');
Route::post('ratings', [RatingController::class, 'store'])->middleware('auth:api')->name('ratings.store');
Route::match(['put', 'patch'], 'ratings/{rating}', [RatingController::class, 'update'])->middleware('auth:api')->name('ratings.update');
Route::delete('ratings/{rating}', [RatingController::class, 'destroy'])->middleware('auth:api')->name('ratings.destroy');

// Faq Routes (home, husbandry)
Route::get('faqs', [FaqController::class, 'index'])->name('faqs.index');
Route::get('faqs/{faq}', [FaqController::class, 'show'])->name('faqs.show');
Route::post('faqs', [FaqController::class, 'store'])->middleware('auth:api')->name('faqs.store');
Route::match(['put', 'patch'], 'faqs/{faq}', [FaqController::class, 'update'])->middleware('auth:api')->name('faqs.update');
Route::delete('faqs/{faq}', [FaqController::class, 'destroy'])->middleware('auth:api')->name('faqs.destroy');

// Log Routes
Route::delete('logs/{log}', [LogController::class, 'destroy'])->middleware('auth:api')->name('logs.destroy');
Route::get('logs', [LogController::class, 'index'])->name('logs.index');
Route::get('logs/{log}', [LogController::class, 'show'])->name('logs.show');
Route::post('logs', [LogController::class, 'store'])->middleware('auth:api')->name('logs.store');
Route::put('logs/{log}', [LogController::class, 'update'])->middleware('auth:api')->name('logs.update');

// Menu Routes
Route::get('menus', [MenuController::class, 'index'])->name('menus.index');
Route::get('menus/{menu:title}', [MenuController::class, 'show'])->name('menus.show');
Route::get('menus/{menu}', [MenuController::class, 'show'])->name('menus.show');

// Notification Routes
Route::get('notifications', [NotificationController::class, 'index'])->middleware('auth:api')->name('users.notifications');
Route::match(['put', 'patch'], 'notifications', [NotificationController::class, 'update'])->middleware('auth:api')->name('users.notifications.update');
Route::delete('notifications/{notification?}', [NotificationController::class, 'destroy'])->middleware('auth:api')->name('users.notifications.destroy');
Route::post('notifications/read/{notification?}', ReadNotificationController::class)->middleware('auth:api')->name('users.read.notifications');

// Offer Routes (project exit / sell flow)
Route::get('offers', [OfferController::class, 'index'])->middleware('auth:api')->name('offers.index');
Route::post('offers', [OfferController::class, 'store'])->middleware('auth:api')->name('offers.store');
Route::get('offers/{offer}', [OfferController::class, 'show'])->middleware('auth:api')->name('offers.show');
Route::match(['put', 'patch'], 'offers/{offer}', [OfferController::class, 'update'])->middleware('auth:api')->name('offers.update');
Route::delete('offers/{offer}', [OfferController::class, 'destroy'])->middleware('auth:api')->name('offers.destroy');

// Order Routes (cart checkout)
Route::get('orders', [OrderController::class, 'index'])->middleware('auth:api')->name('orders.index');
Route::post('orders', [OrderController::class, 'store'])->middleware('auth:api')->name('orders.store');
Route::get('orders/{order}', [OrderController::class, 'show'])->middleware('auth:api')->name('orders.show');
Route::match(['put', 'patch'], 'orders/{order}', [OrderController::class, 'update'])->middleware('auth:api')->name('orders.update');
Route::delete('orders/{order}', [OrderController::class, 'destroy'])->middleware('auth:api')->name('orders.destroy');

// Otp Routes
Route::post('otp', [OtpController::class, 'store'])->name('otp.store');

// Page Routes (about, static pages)
Route::get('pages', [PageController::class, 'index'])->name('pages.index');
Route::get('pages/{page:slug}', [PageController::class, 'show'])->name('pages.show');
Route::post('pages', [PageController::class, 'store'])->middleware('auth:api')->name('pages.store');
Route::match(['put', 'patch'], 'pages/{page}', [PageController::class, 'update'])->middleware('auth:api')->name('pages.update');
Route::delete('pages/{page}', [PageController::class, 'destroy'])->middleware('auth:api')->name('pages.destroy');

// Payment Routes
Route::get('payments', [PaymentController::class, 'index'])->middleware('auth:api')->name('payments.index');
Route::delete('payments/{payment}', [PaymentController::class, 'destroy'])->middleware('auth:api')->name('payments.destroy');
Route::get('payments/{payment}', [PaymentController::class, 'show'])->name('payments.show');
Route::match(['put', 'patch'], 'payments/{payment}', [PaymentController::class, 'update'])->middleware('auth:api')->name('payments.update');
Route::post('payments', [PaymentController::class, 'store'])->middleware('auth:api')->name('payments.store');
Route::get('payments/{payment}/verify', PaymentVerifyController::class)->name('payments.verify');
Route::any('pay/verify/{payment}', VerifyPaymentController::class)->name('payments.pay.verify');

// Post Routes
Route::get('posts', [PostController::class, 'index'])->name('posts.index');
Route::get('posts/{post:slug}', [PostController::class, 'show'])->name('posts.show');
Route::get('landing/posts', PostLandingController::class)->name('posts.landing');
Route::get('popular-posts', PostPopularController::class)->name('posts.popular');
Route::get('posts-increase-view/{post:slug}', PostIncreaseViewController::class)->name('posts.increase.view');
Route::get('posts-published', PostPublishedController::class)->name('posts.published');
Route::get('related/{post:slug}/posts', PostRelatedController::class)->name('posts.related');
Route::get('categories/{category:slug}/posts', PostCategoryController::class)->name('posts.category');

// Producer Routes (sellers)
Route::get('producers', [ProducerController::class, 'index'])->name('producers.index');
Route::get('producers/{producer}', [ProducerController::class, 'show'])->name('producers.show');
Route::post('producers', [ProducerController::class, 'store'])->middleware('auth:api')->name('producers.store');
Route::match(['put', 'patch'], 'producers/{producer}', [ProducerController::class, 'update'])->middleware('auth:api')->name('producers.update');
Route::delete('producers/{producer}', [ProducerController::class, 'destroy'])->middleware('auth:api')->name('producers.destroy');

// Product Routes (shop)
Route::get('products', [ProductController::class, 'index'])->name('products.index');
Route::get('products/{product}', [ProductController::class, 'show'])->name('products.show');
Route::post('products', [ProductController::class, 'store'])->middleware('auth:api')->name('products.store');
Route::match(['put', 'patch'], 'products/{product}', [ProductController::class, 'update'])->middleware('auth:api')->name('products.update');
Route::delete('products/{product}', [ProductController::class, 'destroy'])->middleware('auth:api')->name('products.destroy');

// Project Routes (dashboard)
Route::middleware('auth:api')->group(function (): void {
    Route::get('projects/overview', ProjectOverviewController::class)->name('projects.overview');
    Route::get('projects/overview/profit-chart', [ProjectProfitChartController::class, 'overview'])->name('projects.overview.profit-chart');
    Route::get('projects/history', ProjectHistoryController::class)->name('projects.history');
    Route::get('projects/completable', [ProjectCompletionController::class, 'completable'])->name('projects.completable');
    Route::get('projects/{project}/hub', ProjectHubController::class)->name('projects.hub');
    Route::get('projects/{project}/finance', ProjectFinanceController::class)->name('projects.finance');
    Route::get('projects/{project}/profit-chart', [ProjectProfitChartController::class, 'show'])->name('projects.profit-chart');
    Route::get('projects/{project}/growth', ProjectGrowthController::class)->name('projects.growth');
    Route::get('projects/{project}/health', ProjectHealthController::class)->name('projects.health');
    Route::get('projects/{project}/ration', ProjectRationController::class)->name('projects.ration');
    Route::get('projects/{project}/gallery', ProjectGalleryController::class)->name('projects.gallery');
    Route::post('projects/{project}/gallery', [ProjectMediaController::class, 'storeGallery'])->name('projects.gallery.store');
    Route::put('projects/{project}/gallery/{media}', [ProjectMediaController::class, 'updateGallery'])->name('projects.gallery.update');
    Route::get('projects/{project}/documents', ProjectDocumentController::class)->name('projects.documents');
    Route::post('projects/{project}/documents', [ProjectMediaController::class, 'storeDocument'])->name('projects.documents.store');
    Route::put('projects/{project}/documents/{media}', [ProjectMediaController::class, 'updateDocument'])->name('projects.documents.update');
    Route::post('projects/{project}/media/{media}/flag', [ProjectMediaController::class, 'flag'])->name('projects.media.flag');
    Route::get('projects/{project}/producer-stats', [ProjectMediaController::class, 'producerStats'])->name('projects.producer-stats');
    Route::get('projects/{project}/transactions', ProjectTransactionController::class)->name('projects.transactions');
    Route::get('projects/{project}/comments', [ProjectCommentController::class, 'index'])->name('projects.comments.index');
    Route::post('projects/{project}/comments', [ProjectCommentController::class, 'store'])->name('projects.comments.store');
    Route::post('projects/{project}/ratings', [ProjectRatingController::class, 'store'])->name('projects.ratings.store');

    Route::get('projects/{project}/contract', [ProjectContractController::class, 'show'])->name('projects.contract.show');
    Route::post('projects/{project}/contract/send-code', [ProjectContractController::class, 'sendCode'])->name('projects.contract.send-code');
    Route::post('projects/{project}/contract/confirm', [ProjectContractController::class, 'confirm'])->name('projects.contract.confirm');

    Route::get('projects/{project}/completion', [ProjectCompletionController::class, 'show'])->name('projects.completion.show');
    Route::post('projects/{project}/completion/start', [ProjectCompletionController::class, 'start'])->name('projects.completion.start');
    Route::post('projects/{project}/completion/confirm', [ProjectCompletionController::class, 'confirm'])->name('projects.completion.confirm');
    Route::post('projects/{project}/completion/finalize', [ProjectCompletionController::class, 'finalize'])->name('projects.completion.finalize');

    Route::patch('projects/{project}/sale-registration', [ProjectController::class, 'updateSaleRegistration'])->name('projects.sale-registration');
});
Route::get('projects', [ProjectController::class, 'index'])->middleware('auth:api')->name('projects.index');
Route::post('projects', [ProjectController::class, 'store'])->middleware('auth:api')->name('projects.store');
Route::get('projects/by-code/{project:code}', [ProjectController::class, 'show'])->name('projects.show.by-code');
Route::get('projects/{project}', [ProjectController::class, 'show'])->middleware('auth:api')->name('projects.show');
Route::match(['put', 'patch'], 'projects/{project}', [ProjectController::class, 'update'])->middleware('auth:api')->name('projects.update');
Route::delete('projects/{project}', [ProjectController::class, 'destroy'])->middleware('auth:api')->name('projects.destroy');

// Producer project requests
Route::middleware('auth:api')->prefix('project-requests')->group(function (): void {
    Route::get('/', [ProjectRequestController::class, 'index'])->name('project-requests.index');
    Route::post('/', [ProjectRequestController::class, 'store'])->name('project-requests.store');
    Route::get('{project_request}', [ProjectRequestController::class, 'show'])->name('project-requests.show');
    Route::patch('{project_request}/status', [ProjectRequestController::class, 'updateStatus'])->name('project-requests.status');
    Route::post('{project_request}/message', [ProjectRequestController::class, 'message'])->name('project-requests.message');
});

// Invoice Routes
Route::middleware('auth:api')->group(function (): void {
    Route::get('invoices', [InvoiceController::class, 'index'])->name('invoices.index');
    Route::post('invoices', [InvoiceController::class, 'store'])->name('invoices.store');
    Route::get('projects/{project}/invoice-recipients', [InvoiceController::class, 'recipients'])->name('projects.invoice-recipients');
    Route::get('invoices/{invoice}', [InvoiceController::class, 'show'])->name('invoices.show');
    Route::get('invoices/{invoice}/download', [InvoiceController::class, 'download'])->name('invoices.download');
    Route::match(['put', 'patch'], 'invoices/{invoice}', [InvoiceController::class, 'update'])->name('invoices.update');
    Route::delete('invoices/{invoice}', [InvoiceController::class, 'destroy'])->name('invoices.destroy');
    Route::post('invoices/{invoice}/submit', [InvoiceController::class, 'submit'])->name('invoices.submit');
    Route::post('invoices/{invoice}/approve', [InvoiceController::class, 'approve'])->name('invoices.approve');
    Route::post('invoices/{invoice}/reject', [InvoiceController::class, 'reject'])->name('invoices.reject');
    Route::post('invoices/{invoice}/needs-edit', [InvoiceController::class, 'needsEdit'])->name('invoices.needs-edit');
    Route::post('invoices/{invoice}/pay', PayInvoiceController::class)->name('invoices.pay');
});

// Wallet Routes
Route::middleware('auth:api')->prefix('wallet')->group(function (): void {
    Route::get('/', WalletSummaryController::class)->name('wallet.summary');
    Route::get('transactions', [WalletTransactionController::class, 'index'])->name('wallet.transactions.index');
    Route::get('transactions/{walletTransaction}', [WalletTransactionController::class, 'show'])->name('wallet.transactions.show');
    Route::get('withdrawals', [WithdrawalRequestController::class, 'index'])->name('wallet.withdrawals.index');
    Route::post('withdrawals', [WithdrawalRequestController::class, 'store'])->name('wallet.withdrawals.store');
    Route::get('withdrawals/{withdrawalRequest}', [WithdrawalRequestController::class, 'show'])->name('wallet.withdrawals.show');
    Route::post('deposit', WalletDepositController::class)->name('wallet.deposit');

    Route::get('bank-cards', [BankCardController::class, 'index'])->name('wallet.bank-cards.index');
    Route::post('bank-cards', [BankCardController::class, 'store'])->name('wallet.bank-cards.store');
    Route::get('bank-cards/{bankCard}', [BankCardController::class, 'show'])->name('wallet.bank-cards.show');
    Route::match(['put', 'patch'], 'bank-cards/{bankCard}', [BankCardController::class, 'update'])->name('wallet.bank-cards.update');
    Route::delete('bank-cards/{bankCard}', [BankCardController::class, 'destroy'])->name('wallet.bank-cards.destroy');
    Route::post('bank-cards/{bankCard}/default', [BankCardController::class, 'setDefault'])->name('wallet.bank-cards.default');
});

// Support Ticket Routes
Route::middleware('auth:api')->prefix('support-tickets')->group(function (): void {
    Route::get('/', [SupportTicketController::class, 'index'])->name('support-tickets.index');
    Route::post('/', [SupportTicketController::class, 'store'])->name('support-tickets.store');
    Route::get('{support_ticket:code}', [SupportTicketController::class, 'show'])->name('support-tickets.show');
    Route::post('{support_ticket:code}/replies', [SupportTicketReplyController::class, 'store'])->name('support-tickets.replies.store');
    Route::patch('{support_ticket:code}/close', [SupportTicketController::class, 'close'])->name('support-tickets.close');
});

// Topic Discussions (بحث‌های موضوعی)
Route::middleware('auth:api')->prefix('discussions')->group(function (): void {
    Route::get('/', [DiscussionController::class, 'index'])->name('discussions.index');
    Route::get('history', [DiscussionController::class, 'history'])->name('discussions.history');
    Route::post('/', [DiscussionController::class, 'store'])->name('discussions.store');
    Route::get('{discussion}', [DiscussionController::class, 'show'])->name('discussions.show');
    Route::match(['put', 'patch'], '{discussion}', [DiscussionController::class, 'update'])->name('discussions.update');
    Route::post('{discussion}/end', [DiscussionController::class, 'end'])->name('discussions.end');
    Route::delete('{discussion}', [DiscussionController::class, 'destroy'])->name('discussions.destroy');

    Route::post('{discussion}/messages', [DiscussionMessageController::class, 'store'])->name('discussions.messages.store');
    Route::delete('{discussion}/messages/{discussion_message}', [DiscussionMessageController::class, 'destroy'])->name('discussions.messages.destroy');

    Route::post('{discussion}/participants/{user}/block', [DiscussionParticipantController::class, 'block'])->name('discussions.participants.block');
    Route::delete('{discussion}/participants/{user}/block', [DiscussionParticipantController::class, 'unblock'])->name('discussions.participants.unblock');
});

// Report Routes (project health, growth, ration)
Route::get('reports', [ReportController::class, 'index'])->middleware('auth:api')->name('reports.index');
Route::post('reports', [ReportController::class, 'store'])->middleware('auth:api')->name('reports.store');
Route::get('reports/{report}', [ReportController::class, 'show'])->middleware('auth:api')->name('reports.show');
Route::match(['put', 'patch'], 'reports/{report}', [ReportController::class, 'update'])->middleware('auth:api')->name('reports.update');
Route::delete('reports/{report}', [ReportController::class, 'destroy'])->middleware('auth:api')->name('reports.destroy');

// Growth reports (گزارشات رشد)
Route::middleware('auth:api')->prefix('growth-reports')->group(function (): void {
    Route::get('/', [GrowthReportController::class, 'index'])->name('growth-reports.index');
    Route::get('overview', [GrowthReportController::class, 'overview'])->name('growth-reports.overview');
    Route::post('/', [GrowthReportController::class, 'store'])->name('growth-reports.store');
    Route::get('{report}', [GrowthReportController::class, 'show'])->name('growth-reports.show');
    Route::match(['put', 'patch'], '{report}', [GrowthReportController::class, 'update'])->name('growth-reports.update');
    Route::delete('{report}', [GrowthReportController::class, 'destroy'])->name('growth-reports.destroy');
    Route::post('{report}/submit', [GrowthReportController::class, 'submit'])->name('growth-reports.submit');
    Route::post('{report}/approve', [GrowthReportController::class, 'approve'])->name('growth-reports.approve');
    Route::post('{report}/reject', [GrowthReportController::class, 'reject'])->name('growth-reports.reject');
    Route::post('{report}/needs-edit', [GrowthReportController::class, 'needsEdit'])->name('growth-reports.needs-edit');
    Route::patch('{report}/items/{report_item}/action', [GrowthReportController::class, 'updateItemAction'])->name('growth-reports.items.action');
});

Route::middleware('auth:api')->group(function (): void {
    Route::get('projects/{project}/growth-history', [GrowthReportController::class, 'history'])->name('projects.growth-history');
    Route::get('projects/{project}/growth-products/{productId}', [GrowthReportController::class, 'productSeries'])->name('projects.growth-products');
    Route::get('projects/{project}/health-history', [HealthReportController::class, 'history'])->name('projects.health-history');
    Route::get('projects/{project}/health-latest', [HealthReportController::class, 'latest'])->name('projects.health-latest');
    Route::get('projects/{project}/ration-history', [RationReportController::class, 'history'])->name('projects.ration-history');
    Route::get('projects/{project}/ration-current', [RationReportController::class, 'current'])->name('projects.ration-current');
    Route::get('projects/{project}/ration-feeding', [RationReportController::class, 'feedingSchedule'])->name('projects.ration-feeding');
    Route::post('projects/{project}/ration-feeding', [RationReportController::class, 'storeFeedingLog'])->name('projects.ration-feeding.store');
});

// Health reports (گزارشات سلامت و درمان)
Route::middleware('auth:api')->prefix('health-reports')->group(function (): void {
    Route::get('/', [HealthReportController::class, 'index'])->name('health-reports.index');
    Route::post('/', [HealthReportController::class, 'store'])->name('health-reports.store');
    Route::get('{report}', [HealthReportController::class, 'show'])->name('health-reports.show');
    Route::match(['put', 'patch'], '{report}', [HealthReportController::class, 'update'])->name('health-reports.update');
    Route::delete('{report}', [HealthReportController::class, 'destroy'])->name('health-reports.destroy');
    Route::post('{report}/submit', [HealthReportController::class, 'submit'])->name('health-reports.submit');
    Route::post('{report}/approve', [HealthReportController::class, 'approve'])->name('health-reports.approve');
    Route::post('{report}/reject', [HealthReportController::class, 'reject'])->name('health-reports.reject');
    Route::post('{report}/needs-edit', [HealthReportController::class, 'needsEdit'])->name('health-reports.needs-edit');
    Route::get('{report}/download', [HealthReportController::class, 'download'])->name('health-reports.download');
});

// Under-treatment products (محصولات تحت درمان / تحت نظر)
Route::middleware('auth:api')->prefix('health-treatments')->group(function (): void {
    Route::get('/', [HealthTreatmentController::class, 'index'])->name('health-treatments.index');
    Route::get('{healthTreatment}', [HealthTreatmentController::class, 'show'])->name('health-treatments.show');
    Route::get('{healthTreatment}/history', [HealthTreatmentController::class, 'history'])->name('health-treatments.history');
    Route::post('{healthTreatment}/updates', [HealthTreatmentController::class, 'storeUpdate'])->name('health-treatments.updates.store');
});

// Ration / feeding reports (جیره و تغذیه)
Route::middleware('auth:api')->prefix('ration-reports')->group(function (): void {
    Route::get('/', [RationReportController::class, 'index'])->name('ration-reports.index');
    Route::post('/', [RationReportController::class, 'store'])->name('ration-reports.store');
    Route::get('{report}', [RationReportController::class, 'show'])->name('ration-reports.show');
    Route::match(['put', 'patch'], '{report}', [RationReportController::class, 'update'])->name('ration-reports.update');
    Route::delete('{report}', [RationReportController::class, 'destroy'])->name('ration-reports.destroy');
    Route::post('{report}/submit', [RationReportController::class, 'submit'])->name('ration-reports.submit');
    Route::post('{report}/approve', [RationReportController::class, 'approve'])->name('ration-reports.approve');
    Route::post('{report}/reject', [RationReportController::class, 'reject'])->name('ration-reports.reject');
    Route::post('{report}/needs-edit', [RationReportController::class, 'needsEdit'])->name('ration-reports.needs-edit');
});

// Service Routes
Route::get('services', [ServiceController::class, 'index'])->name('services.index');
Route::get('services/{service}', [ServiceController::class, 'show'])->name('services.show');
Route::post('services', [ServiceController::class, 'store'])->middleware('auth:api')->name('services.store');
Route::match(['put', 'patch'], 'services/{service}', [ServiceController::class, 'update'])->middleware('auth:api')->name('services.update');
Route::delete('services/{service}', [ServiceController::class, 'destroy'])->middleware('auth:api')->name('services.destroy');

// Setting Routes
Route::get('settings', [SettingController::class, 'index'])->name('settings.index');
Route::get('settings/{setting}', [SettingController::class, 'show'])->name('settings.show');

// Tag Routes (blog filters)
Route::get('tags', [TagController::class, 'index'])->name('tags.index');
Route::get('tags/{tag}', [TagController::class, 'show'])->name('tags.show');
Route::post('tags', [TagController::class, 'store'])->middleware('auth:api')->name('tags.store');
Route::match(['put', 'patch'], 'tags/{tag}', [TagController::class, 'update'])->middleware('auth:api')->name('tags.update');
Route::delete('tags/{tag}', [TagController::class, 'destroy'])->middleware('auth:api')->name('tags.destroy');

// User Routes (frontend auth/profile — admin user management is Filament-only)
Route::post('uploads', [FileUploadController::class, 'store'])->middleware('auth:api')->name('uploads.store');
Route::get('user', [AuthProfileController::class, 'me'])->middleware('auth:api')->name('users.show');
Route::match(['put', 'patch'], 'user', [AuthProfileController::class, 'update'])->middleware('auth:api')->name('users.update.self');
Route::match(['put', 'patch'], 'users/{routeUser}', [AuthProfileController::class, 'updateById'])->middleware('auth:api')->name('users.edit');
Route::delete('users/{routeUser}', [UserController::class, 'destroy'])->middleware('auth:api')->name('users.destroy');
Route::get('users-dashboard', DashboardController::class)->middleware('auth:api')->name('users.dashboard');
Route::post('authenticate', AuthenticateController::class)->name('authenticate');
Route::post('forget-password', ForgetController::class)->name('users.forget.password');
Route::post('login/{refreshToken?}', LoginController::class)->name('login');
Route::post('logout', LogoutController::class)->middleware('auth:api')->name('users.logout');
Route::post('register', RegisterController::class)->name('register');
Route::post('register/employer', [AuthProfileController::class, 'registerEmployer'])->name('register.employer');
Route::get('user-transactions', UserTransactionsController::class)->middleware('auth:api')->name('user.transactions');
