<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;

// 사용자
use App\Http\Controllers\Account;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\RegisterController;
use App\Http\Controllers\Auth\ForgotAccountController;
use App\Http\Controllers\MainController;
use App\Http\Controllers\DocumentController;
use App\Http\Controllers\Board\BoardController;
use App\Http\Controllers\Board\PostController;
use App\Http\Controllers\Board\CommentController;
use App\Http\Controllers\Board\TagController;
use App\Http\Controllers\Movie;
use App\Http\Controllers\ApiController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

/*
Route::get('/', function () {
    return view('welcome');
});
*/

Auth::routes(['verify' => true]);

Route::get('/', [MainController::class, 'index'])->name('main');

/**
|--------------------------------------------------------------------------
| 사용자
|--------------------------------------------------------------------------
 */
// 로그아웃
Route::get('/logout', [LoginController::class, 'logout'])->name('logout');

Route::prefix('auth')->name('auth.')->group(function()
{
    // 아이디 찾기
    Route::get('/findID', [ForgotAccountController::class, 'index'])->name('findID');
    Route::post('/findID/requestTossCert', [ForgotAccountController::class, 'requestTossCert'])->name('findID.requestTossCert');
    Route::post('/findID', [ForgotAccountController::class, 'store'])->name('findID.store');

    // 이메일 검증 확인
    Route::post('/register/sendVerifyLink', [RegisterController::class, 'sendVerifyLink'])->name('register.sendVerifyLink');
    Route::get('/register/verifyEmail/{token}', [RegisterController::class, 'verifyEmail'])->middleware('signed')->name('register.verifyEmail');
    Route::post('/register/checkVerifiedEmail', [RegisterController::class, 'checkVerifiedEmail'])->name('register.checkVerifiedEmail');
});

// 문서
Route::get('/document/{code}', [DocumentController::class, 'index'])->name('document');

// 게시판 이미지 첨부 기능
Route::get('/editor/uploader', [ApiController::class, 'uploader'])->name('uploader');

/**
 * 내부 API 호출
 */
Route::prefix('api')->name('api.')->group(function()
{
    Route::get('/loginCheck', [ApiController::class, 'loginCheck'])->name('loginCheck');
    Route::post('/filterSpamKeyword', [ApiController::class, 'filterSpamKeyword'])->name('filterSpamKeyword');
    Route::post('/isEmailAble', [ApiController::class, 'isEmailAble'])->name('isEmailAble');
    Route::post('/isPhoneAble', [ApiController::class, 'isPhoneAble'])->name('isPhoneAble');
    Route::post('/isPasswordAble', [ApiController::class, 'isPasswordAble'])->name('isPasswordAble');
    Route::post('/isNicknameAble', [ApiController::class, 'isNicknameAble'])->name('isNicknameAble');
    Route::post('/passwordCampaignSkip', [ApiController::class, 'passwordCampaignSkip'])->name('passwordCampaignSkip');
    Route::get('/movie/review/latest/{movieCd}', [ApiController::class, 'movieReviewLatest'])->name('movieReviewLatest');
});

/**
|--------------------------------------------------------------------------
| 게시판
|--------------------------------------------------------------------------
 */
Route::prefix('board')->name('board.')->group(function()
{
    // 게시판
    Route::get('/{code}', [BoardController::class, 'index'])->name('list');
    Route::get('/{code}/write', [PostController::class, 'write'])->name('post.write');
    Route::post('/{code}/store', [PostController::class, 'store'])->name('post.store');

    // 게시글
    Route::get('/{code}/{postID}', [PostController::class, 'view'])->whereNumber('postID')->name('post.view');
    Route::get('/{code}/{postID}/edit', [PostController::class, 'edit'])->whereNumber('postID')->name('post.edit');
    Route::put('/{code}/{postID}/update', [PostController::class, 'update'])->whereNumber('postID')->name('post.update');
    Route::delete('/{code}/{postID}/delete', [PostController::class, 'delete'])->whereNumber('postID')->name('post.delete');
    Route::post('/{code}/{postID}/blame', [PostController::class, 'blame'])->whereNumber('postID')->name('post.blame');
    Route::post('/{code}/{postID}/bookmark', [PostController::class, 'bookmark'])->whereNumber('postID')->name('post.bookmark');
    Route::post('/{code}/{postID}/like', [PostController::class, 'like'])->whereNumber('postID')->name('post.like');
    Route::post('/{code}/{postID}/dislike', [PostController::class, 'dislike'])->whereNumber('postID')->name('post.dislike');
    Route::post('/{code}/{postID}/download', [PostController::class, 'download'])->whereNumber('postID')->name('post.download');
    Route::post('/{code}/{postID}/link', [PostController::class, 'link'])->whereNumber('postID')->name('post.link');
    Route::get('/{code}/uploader', [PostController::class, 'uploader'])->name('post.uploader');

    // 댓글
    Route::get('/{code}/{postID}/comment', [CommentController::class, 'index'])->whereNumber('postID')->name('post.comment');
    Route::post('/{code}/{postID}/comment/store', [CommentController::class, 'store'])->whereNumber('postID')->name('post.comment.store');
    Route::put('/{code}/{postID}/comment/update', [CommentController::class, 'update'])->whereNumber('postID')->name('post.comment.update');
    Route::post('/{code}/{postID}/comment/reply', [CommentController::class, 'reply'])->whereNumber('postID')->name('post.comment.reply');
    Route::delete('/{code}/{postID}/comment/delete', [CommentController::class, 'delete'])->whereNumber('postID')->name('post.comment.delete');
    Route::post('/{code}/{postID}/comment/blame', [CommentController::class, 'blame'])->whereNumber('postID')->name('post.comment.blame');
    Route::post('/{code}/{postID}/comment/like', [CommentController::class, 'like'])->whereNumber('postID')->name('post.comment.like');
    Route::post('/{code}/{postID}/comment/dislike', [CommentController::class, 'dislike'])->whereNumber('postID')->name('post.comment.dislike');
});


/**
|--------------------------------------------------------------------------
| 태그
|--------------------------------------------------------------------------
 */
 /*
Route::prefix('tag')->name('tag.')->group(function()
{
    Route::get('/', [TagController::class, 'index'])->name('index');
    Route::get('/posts', [TagController::class, 'posts'])->name('posts');
});
*/

/**
|--------------------------------------------------------------------------
| 내 정보 수정
|--------------------------------------------------------------------------
 */
Route::prefix('account')->name('account.')->group(function()
{
    // 내 정보
    Route::get('/', [Account\ProfileController::class, 'index'])->name('profile');

    // 비밀번호 확인
    Route::get('/certify', [Account\CertifyController::class, 'index'])->name('certify');
    Route::post('/certify/update', [Account\CertifyController::class, 'update'])->name('certify.update');

    // 회원 정보 수정
    Route::get('/modify', [Account\ModifyController::class, 'index'])->name('modify');
    Route::post('/modify/update', [Account\ModifyController::class, 'update'])->name('modify.update');

    // 회원 정보 수정 - 이메일 변경하기
    Route::get('/email', [Account\EmailController::class, 'index'])->name('email');
    Route::post('/email/update', [Account\EmailController::class, 'update'])->name('email.update');

    // 비밀번호 변경
    Route::get('/password', [Account\PasswordChangeController::class, 'index'])->name('password');
    Route::post('/password/update', [Account\PasswordChangeController::class, 'update'])->name('password.update');

    // 정기 비밀번호 변경 안내
    Route::get('/password/campaign', [Account\PasswordCampaignController::class, 'index'])->name('password.campaign');
    Route::post('/password/campaign/update', [Account\PasswordCampaignController::class, 'update'])->name('password.campaign.update');

    // 로그인 기록
    Route::get('/loginLog', [Account\LoginLogController::class, 'index'])->name('loginLog');
    Route::post('/loginLog', [Account\LoginLogController::class, 'index'])->name('loginLog');

    // 회원탈퇴
    Route::get('/leave', [Account\LeaveController::class, 'index'])->name('leave');
    Route::post('/leave/update', [Account\LeaveController::class, 'update'])->name('leave.update');

    // 작성 게시글
    Route::get('/post', [Account\PostController::class, 'index'])->name('post');
    Route::post('/post', [Account\PostController::class, 'index'])->name('post');
    Route::delete('/post/delete', [Account\PostController::class, 'delete'])->name('post.delete');

    // 작성 댓글
    Route::get('/comment', [Account\CommentController::class, 'index'])->name('comment');
    Route::post('/comment', [Account\CommentController::class, 'index'])->name('comment');
    Route::delete('/comment/delete', [Account\CommentController::class, 'delete'])->name('comment.delete');
});

/**
 * 영화 정보 제공
 */
Route::prefix('movie')->name('movie.')->group(function()
{
    Route::resource('/rank', Movie\RankController::class)->names('rank');
    Route::resource('/search', Movie\SearchController::class)->names('search');
    Route::resource('/trailer', Movie\TrailerController::class)->names('trailer');

    Route::post('/review/like', [Movie\ReviewController::class, 'like'])->name('review.like');
    Route::post('/review/dislike', [Movie\ReviewController::class, 'dislike'])->name('review.dislike');
    Route::post('/review/blame', [Movie\ReviewController::class, 'blame'])->name('review.blame');
    Route::resource('/review', Movie\ReviewController::class)->names('review');
});


// 관리자
require_once ('admin.php');
