<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
//use App\Http\Controllers\PenyataController;
use App\Http\Controllers\API\v1\Voter\PenyataController;
use App\Http\Controllers\API\v1\Voter\VoterController;
use App\Http\Controllers\API\v1\Admin\Penyata\GetController;



/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// Route::middleware('auth:api')->get('/user', function (Request $request) {
//     return $request->user();
// });
Route::get('/user', 'Auth\UserController@index')->middleware('auth:api');


Route::prefix('v1')->group(function () { //Version 1 of my Rest API
	//Voters API
	Route::post('voter/login', 'API\v1\Voter\LoginController');
	Route::post('voter/verify', 'API\v1\Voter\LoginController@verifyTAC');

	Route::middleware(['auth:voterAPI', 'voter'])->group(function () {
		Route::get('election/information', 'API\v1\Election\InformationController');
		Route::post('election/vote', 'API\v1\Election\VoteController')->middleware(['fizikal_registration_verified', 'isvoted']);
		Route::get('election/result', 'API\v1\Election\ResultController')->middleware('has_voted');
		Route::post('allowance/code', 'API\v1\Allowance\ClaimCodeController');
		Route::get('portal-settings', 'API\v1\PortalSettings\GetController');
		Route::post('voter/logout', 'API\v1\Voter\LogoutController');
	});

	Route::prefix('attendance')->group(function () {
		Route::put('{id}', 'API\v1\Voter\AttendanceController');
	});

	Route::get('physical-attendance-gate/current', 'API\v1\PhysicalAttendanceGateController')
		->middleware('physical_gate_display');

	Route::get('public/roulette/fizikal-voters', 'API\v1\RouletteFizikalVotersController');

	//Admins API
	Route::post('admin/login', 'API\v1\Admin\LoginController'); //Excluding Login for auth middleware

	Route::middleware(['auth:api', 'admin', 'election', 'attendance_committee_role'])->group(function () {

		Route::prefix('admin')->group(function () { //Route /api/v1/admin
			Route::get('information', 'API\v1\Admin\InformationController');
			Route::get('logout', 'API\v1\Admin\LogoutController');
			Route::get('activity-log', 'API\v1\Admin\ActivityLog\IndexController');
			Route::get('portal-settings', 'API\v1\Admin\PortalSettings\GetController');
			Route::post('portal-settings', 'API\v1\Admin\PortalSettings\UpdateController');
			Route::post('impersonate', 'API\v1\Admin\Impersonate\StartController')->middleware('main_admin');
			Route::post('impersonate/leave', 'API\v1\Admin\Impersonate\LeaveController');
			Route::get('{id}', 'API\v1\Admin\GetController@show');
			Route::put('{id}', 'API\v1\Admin\UpdateController');
			Route::put('password/{id}', 'API\v1\Admin\UpdateController@updatePassword');
			Route::post('', 'API\v1\Admin\AddController')->middleware('main_admin');
			Route::get('', 'API\v1\Admin\GetController')->middleware('main_admin');
			Route::delete('{id}', 'API\v1\Admin\DeleteController')->middleware('main_admin');
		});

		Route::prefix('election')->group(function () {
			Route::get('result/{id}', 'API\v1\Election\ResultController@finalResult');
			Route::get('{id}/attendance-summary', 'API\v1\Election\AttendanceSummaryController');
			Route::get('results', 'API\v1\Election\ResultController');
			Route::post('start', 'API\v1\Election\StartController');
			Route::post('stop', 'API\v1\Election\StopController');
			Route::post('register-next', 'API\v1\Election\RegisterNextSessionController');
			Route::get('', 'API\v1\Election\GetController');
		});

		Route::prefix('position')->group(function () {
			Route::post('', 'API\v1\Position\AddPositionController');
			Route::get('', 'API\v1\Position\GetPositionController');
			Route::delete('{id}', 'API\v1\Position\DeletePositionController');
			Route::put('{id}', 'API\v1\Position\UpdatePositionController');
		});

		Route::prefix('partylist')->group(function () {
			Route::post('', 'API\v1\Partylist\AddController');
			Route::get('',	'API\v1\Partylist\GetController');
			Route::delete('{id}', 'API\v1\Partylist\DeleteController');
			Route::put('{id}',	'API\v1\Partylist\UpdateController');
		});

		Route::prefix('allowance')->group(function () {
			Route::post('payout', 'API\v1\Admin\Allowance\PayoutController');
			Route::post('verify-code', 'API\v1\Admin\Allowance\VerifyCodeController');
			Route::post('void/{id}', 'API\v1\Admin\Allowance\VoidController');
			Route::get('summary', 'API\v1\Admin\Allowance\SummaryController');
		});

		Route::prefix('nominee')->group(function () {
			Route::post('', 'API\v1\Nominee\AddController');
			Route::get('', 'API\v1\Nominee\GetController');
			Route::delete('{id}', 'API\v1\Nominee\DeleteController');
			Route::put('{id}', 'API\v1\Nominee\UpdateController');
		});

		Route::prefix('voter')->group(function () {
			Route::post('', 'API\v1\Voter\AddController');
			Route::get('', 'API\v1\Voter\GetController');
			Route::get('member-catalog', 'API\v1\Voter\AllMembersCatalogController');
			Route::post('sync-applicable', 'API\v1\Voter\SyncApplicableVotersController');
			Route::post('{id}/verify-fizikal-registration', 'API\v1\Voter\VerifyFizikalRegistrationController');
			Route::delete('{id}', 'API\v1\Voter\DeleteController');
			Route::put('{id}', 'API\v1\Voter\UpdateController');
		});

	});

	Route::get('voter', 'API\v1\Voter\GetController');

	Route::get('/penyata/{id}', [PenyataController::class, 'getPenyata']);
	Route::post('/penyata/{id}/sahkan', [PenyataController::class, 'sahkan']);

	Route::get('/penyata/{no_anggota}/pdf', [PenyataController::class, 'pdf']);

	//Route::post('/admin/voter/import', [VoterController::class, 'import']);


});
