<?php

use App\Http\Controllers\ActivityController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\MemberController;
use App\Http\Controllers\ImportController;
use App\Http\Controllers\ScoreController;
use App\Http\Controllers\SiteSettingController;
use App\Http\Controllers\TeamController;
use App\Http\Controllers\UploadProxyController;
use Illuminate\Support\Facades\Route;

Route::post('/login', [AuthController::class, 'login']);
Route::get('/site-settings/public', [SiteSettingController::class, 'publicIndex']);
Route::get('/stats/public', [SiteSettingController::class, 'publicStats']);
Route::get('/img/{path}', [UploadProxyController::class, 'show'])->where('path', '.*');

Route::middleware('auth.bearer')->group(function () {
    Route::get('/me', [AuthController::class, 'me']);
    Route::post('/logout', [AuthController::class, 'logout']);

    // Teams
    Route::get('/teams', [TeamController::class, 'index']);
    Route::post('/teams', [TeamController::class, 'store']);
    Route::get('/teams/{team}', [TeamController::class, 'show']);
    Route::patch('/teams/{team}', [TeamController::class, 'update']);
    Route::delete('/teams/{team}', [TeamController::class, 'destroy']);
    Route::post('/teams/{team}/captain', [TeamController::class, 'setCaptain']);
    Route::post('/teams/{team}/one-time/{activityKey}', [TeamController::class, 'toggleOneTime']);
    Route::post('/teams/{team}/weeks/{weekId}/mcm-bonus', [TeamController::class, 'setMcmBonus']);
    Route::post('/teams/{team}/weeks/{weekId}/tyfcb-bonus', [TeamController::class, 'setTyfcbBonus']);
    Route::post('/teams/{team}/weeks/{weekId}/attendance-bonus', [TeamController::class, 'setAttendanceBonus']);
    Route::post('/teams/{team}/logo', [TeamController::class, 'uploadLogo']);
    Route::delete('/teams/{team}/logo', [TeamController::class, 'deleteLogo']);

    // Members
    Route::post('/teams/{team}/members', [MemberController::class, 'store']);
    Route::patch('/members/{member}', [MemberController::class, 'update']);
    Route::patch('/members/{member}/move', [MemberController::class, 'move']);
    Route::delete('/members/{member}', [MemberController::class, 'destroy']);

    // Activities (Points Master)
    Route::get('/activities', [ActivityController::class, 'index']);
    Route::patch('/activities/{key}', [ActivityController::class, 'update']);

    // Bulk import
    Route::post('/import/teams', [ImportController::class, 'teams']);

    // Weekly scores
    Route::get('/scores/{week}', [ScoreController::class, 'indexByWeek']);
    Route::put('/scores/{member}/{week}', [ScoreController::class, 'upsert']);

    // CMS / Site settings
    Route::get('/site-settings', [SiteSettingController::class, 'index']);
    Route::patch('/site-settings', [SiteSettingController::class, 'bulkUpdate']);
});
