<?php

use MtcPharmacy\ReferAFriend\Http\Controllers\ReferralLandingController;
use MtcPharmacy\ReferAFriend\Http\Controllers\ReferralsController;
use MtcPharmacy\ReferAFriend\Http\Controllers\Admin\ReferralsAdminController;

// Public routes
\Route::group(['middleware' => 'web'], function () {
    \Route::get('refer-a-friend', [ReferralLandingController::class, 'index']);
    \Route::get('refer-a-friend/{code}', [ReferralLandingController::class, 'handleCode'])->middleware('throttle:30,1');
});

// Member routes
\Route::group(['middleware' => ['web', 'account.verified']], function () {
    \Route::get('members/referrals', [ReferralsController::class, 'index'])->name('members-referrals');
    \Route::post('members/referrals/invite', [ReferralsController::class, 'sendInvite'])->middleware('throttle:10,1');
    \Route::post('members/referrals/reminder', [ReferralsController::class, 'sendReminder'])->middleware('throttle:10,1');
    \Route::get('members/referrals/link', [ReferralsController::class, 'getShareLink']);
});

// Admin routes
\Route::group(['middleware' => ['web', 'auth']], function () {
    \Route::get('admin/referrals', [ReferralsAdminController::class, 'dashboard']);
    \Route::get('admin/referrals/detail/{id}', [ReferralsAdminController::class, 'detail']);
    \Route::post('admin/referrals/manual-credit', [ReferralsAdminController::class, 'manualCredit']);
    \Route::post('admin/referrals/revoke/{id}', [ReferralsAdminController::class, 'revokeReward']);
    \Route::get('admin/referrals/emails', [ReferralsAdminController::class, 'emails']);
    \Route::get('admin/referrals/export', [ReferralsAdminController::class, 'export']);
});
