<?php

defined( 'ABSPATH' ) || exit;

use Vendtics\WpMVC\Routing\Route;
use Vendtics\App\Http\Controllers\CampaignJobController;
use Vendtics\App\Http\Controllers\Admin\CampaignController;
use Vendtics\App\Http\Controllers\Admin\CampaignRecipientController;
use Vendtics\App\Http\Controllers\Admin\ContactController;
use Vendtics\App\Http\Controllers\Admin\CountCampaignRecipientController;
use Vendtics\App\Http\Controllers\Admin\EmailController;
use Vendtics\App\Http\Controllers\Admin\ListController;
use Vendtics\App\Http\Controllers\Admin\NoteController;
use Vendtics\App\Http\Controllers\Admin\TagController;
use Vendtics\App\Http\Controllers\Admin\SegmentController;
use Vendtics\App\Http\Controllers\Admin\PageController;
use Vendtics\App\Http\Controllers\Admin\SettingsController;

Route::group(
    'admin', function() {
        Route::group(
            'contacts', function() {
                Route::get( 'tabs', [ContactController::class, 'tabs_count'] );
                Route::get( 'counts', [ContactController::class, 'contact_count'] );
                Route::group(
                    'bulk', function() {
                        Route::delete( '/', [ContactController::class, 'bulk_delete'] );
                        Route::post( 'assign/tags', [ContactController::class, 'bulk_assign_tags'] );
                        Route::post( 'assign/lists', [ContactController::class, 'bulk_assign_lists'] );
                        Route::post( 'unassign/tags', [ContactController::class, 'bulk_unassign_tags'] );
                        Route::post( 'unassign/lists', [ContactController::class, 'bulk_unassign_lists'] );
                        Route::post( 'update/status', [ContactController::class, 'bulk_update_status'] );
                        Route::post( 'update/type', [ContactController::class, 'bulk_update_type'] );
                    }
                );
                Route::group(
                    '{id}', function() {
                        Route::patch( 'status', [ContactController::class, 'update_status'] );
                        Route::patch( 'type', [ContactController::class, 'update_type'] );
                    }
                );
                Route::resource( '/', ContactController::class );
            }
        );

        Route::group(
            'tags', function() {
                Route::get( 'select', [TagController::class, 'select'] );
                Route::delete( 'bulk', [TagController::class, 'bulk_delete'] );
                Route::resource( '/', TagController::class );
            } 
        );

        Route::group(
            'lists', function() {
                Route::get( 'select', [ListController::class, 'select'] );
                Route::delete( 'bulk', [ListController::class, 'bulk_delete'] );
                Route::resource( '/', ListController::class );
            } 
        );

        Route::group(
            'segments', function() {
                Route::get( 'select', [SegmentController::class, 'select'] );
                Route::post( 'duplicate', [SegmentController::class, 'duplicate'] );
                Route::delete( 'bulk', [SegmentController::class, 'bulk_delete'] );
                Route::resource( '/', SegmentController::class );
            } 
        );


        Route::group(
            'notes', function() {
                Route::post( '{id}/duplicate', [NoteController::class, 'duplicate'] );
                Route::post( '{id}/update-favorite-status', [NoteController::class, 'update_favorite_status'] );
                Route::post( '{id}/priority', [NoteController::class, 'update_priority'] );
                Route::resource( '/', NoteController::class );
            } 
        );
        Route::group(
            'emails', function() {
                Route::post( 'test', [EmailController::class, 'send_test_email'] );
            }
        );

        Route::group(
            'campaigns', function() {
                Route::group(
                    '{id}', function() {
                        Route::get( 'recipients', [CampaignRecipientController::class, 'index'] );
                        Route::post( 'status/draft', [CampaignController::class, 'mark_as_draft'] );
                        Route::post( 'status/schedule', [CampaignController::class, 'mark_as_schedule'] );
                        Route::post( 'send-right-now', [CampaignController::class, 'send_right_now'] );
                        Route::patch( 'name', [CampaignController::class, 'update_name'] );
                        Route::group(
                            'jobs', function() {
                                Route::get( 'status', [CampaignJobController::class, 'get_status'] );
                                Route::post( 'pause', [CampaignJobController::class, 'pause'] );
                                Route::post( 'resume', [CampaignJobController::class, 'resume'] );
                                Route::post( 'cancel', [CampaignJobController::class, 'cancel'] );
                            }
                        );
                    }
                );
                
                Route::group(
                    'count-recipients', function() {
                        Route::get( 'tags-lists', [CountCampaignRecipientController::class, 'tags_lists'] );
                        Route::get( 'segment', [CountCampaignRecipientController::class, 'segment'] );
                        Route::get( 'advanced-filter', [CountCampaignRecipientController::class, 'advanced_filter'] );
                    }
                );
                Route::get( 'counts', [CampaignController::class, 'campaigns_count'] );
                Route::delete( 'bulk', [CampaignController::class, 'bulk_delete'] );
                Route::resource( '/', CampaignController::class );
            }
        );

        Route::get( 'settings', [SettingsController::class, 'index'] );
        Route::post( 'settings', [SettingsController::class, 'update'] );
        Route::get( 'pages/select', [PageController::class, 'index'] );
    }, ['admin'] 
);