<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::post('/auth/login', [\App\Http\Controllers\Api\AuthController::class, 'login'])
    ->middleware('throttle:5,1');
Route::post('/auth/signup', [\App\Http\Controllers\Api\AuthController::class, 'signup']);

Route::get('/user', function (Request $request) {
    return $request->user();
})->middleware('auth:sanctum');

Route::middleware('auth:sanctum')
    ->name('auth.')
    ->prefix('auth')
    ->group(function () {
    Route::get('/me', [\App\Http\Controllers\Api\AuthController::class, 'me']);
    Route::post('/logout', [\App\Http\Controllers\Api\AuthController::class, 'logout']);

    // Route::get('/profile', [\App\Http\Controllers\Api\ProfileController::class, 'show']);
    Route::put('/profile/{id}', [\App\Http\Controllers\Api\ProfileController::class, 'update']);
    Route::get('/profile/{id}/download/{type}', [\App\Http\Controllers\Api\ProfileController::class, 'downloadFile']);
    Route::apiResource('/profile', \App\Http\Controllers\Api\ProfileController::class)->except(['create', 'edit', 'destroy']);
});

Route::middleware('auth:sanctum')
    ->name('map.')
    ->prefix('map')
    ->group(function () {
        
    Route::apiResource('/lahan', \App\Http\Controllers\Api\LahanController::class)->except(['create', 'edit']);
    Route::apiResource('/tanaman', \App\Http\Controllers\Api\TanamanController::class)->except(['create', 'edit']);
    Route::apiResource('/inspeksi', \App\Http\Controllers\Api\InspeksiController::class)->except(['create', 'edit']);
    Route::apiResource('/panen', \App\Http\Controllers\Api\PanenController::class)->except(['create', 'edit']);
    Route::apiResource('/offtaker', \App\Http\Controllers\Api\OfftakerController::class)->except(['create', 'edit']);
});

Route::middleware('auth:sanctum')
    ->name('distribusi.')
    ->prefix('distribusi')
    ->group(function () {
        
    Route::apiResource('/panen', \App\Http\Controllers\Api\DistributionController::class)->except(['create', 'edit']);
});

Route::middleware('auth:sanctum')
    ->name('master.')
    ->prefix('master')
    ->group(function () {
        
    Route::apiResource('/komoditas', \App\Http\Controllers\Api\KomoditasController::class)->only(['index', 'show']);

    Route::apiResource('/provinsi', \App\Http\Controllers\Api\ProvinsiController::class)->only(['index', 'show']);
    Route::apiResource('/kabupaten-kota', \App\Http\Controllers\Api\KabupatenKotaController::class)->only(['index', 'show']);
    Route::apiResource('/kecamatan', \App\Http\Controllers\Api\KecamatanController::class)->only(['index', 'show']);
    Route::apiResource('/desa-kelurahan', \App\Http\Controllers\Api\DesaKelurahanController::class)->only(['index', 'show']);
});
Route::middleware('auth:sanctum')
    ->name('manajemen.')
    ->prefix('manajemen')
    ->group(function () {
        
    Route::apiResource('fasilitator', \App\Http\Controllers\Api\FacilitatorController::class);
});