<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\MeterReadingController;
use App\Http\Controllers\InvoiceController;
use App\Http\Controllers\MidtransController;
use App\Http\Controllers\NewsController;

Route::post('/midtrans/callback', [MidtransController::class, 'handleNotification'])
    ->name('midtrans.callback');

Route::get('/', function () {
    return redirect()->route('login');
});
// Grup untuk tamu (yang belum login)
Route::middleware('guest')->group(function () {
    Route::get('/register', [AuthController::class, 'showRegisterForm'])->name('register');
    Route::post('/register', [AuthController::class, 'register'])->name('register.submit');

    Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
    Route::post('/login', [AuthController::class, 'login'])->name('login.submit');

});

// Grup untuk yang sudah login
Route::middleware('auth')->group(function () {
    Route::get('/home', [HomeController::class, 'index'])->name('home');
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

    Route::get('/profile', [ProfileController::class, 'index'])->name('profile.index');
    Route::get('/profile/edit', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::put('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::get('/profile/password', [ProfileController::class, 'editPassword'])->name('profile.password');
    Route::put('/profile/password', [ProfileController::class, 'updatePassword'])->name('profile.password.update');

    Route::get('/meter-reading/create', [MeterReadingController::class, 'create'])->name('meter.create');
    Route::post('/meter-reading', [MeterReadingController::class, 'store'])->name('meter.store');

    Route::get('/invoices', [InvoiceController::class, 'index'])->name('invoices.index');
    Route::get('/invoices/{invoice}', [InvoiceController::class, 'show'])->name('invoices.show');

    Route::get('/news/{id}', [NewsController::class, 'showDetail'])->name('news.show');

    Route::get('/news', [NewsController::class, 'index'])->name('news.index');
    

});