<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

Route::get('/', function () {
    return view('songs.index');
})->name('home');

Route::get('/search', 'SongController@search');
Route::get('/songs/most-visited', 'SongController@mostVisited')->name('songs.most_visited');
Route::get('/lyrics/{song}', 'SongController@show');

// Artists browsing
Route::get('/artists', 'ArtistController@browse')->name('artists.browse');
Route::get('/artists/{letter}', 'ArtistController@byLetter')->name('artists.letter');

// Contact page
Route::get('/contact', 'ContactController@show')->name('contact');
Route::post('/contact', 'ContactController@send')->name('contact.send');

// Artist controller
Route::get('/artist/{artist}', 'ArtistController@show');
Route::get('/artist/edit/{id}', 'ArtistController@edit');
Route::patch('/artist/update/{id}', 'ArtistController@update');
Route::delete('/artist/delete/{id}', 'ArtistController@destroy');


// Admin controller
Route::get('/admin/request', 'AdminController@demand')->name('admin.request');
Route::post('/admin/request/{id}', 'AdminController@store');
Route::delete('/admin/delete/{id}', 'AdminController@destroy');
Route::get('/admin/create/{id}', 'AdminController@create');
Route::get('/admin/edit/{id}', 'AdminController@edit');
Route::patch('/admin/update/{id}', 'AdminController@update');

// Ad management (admin only)
Route::get('/admin/ads', 'AdController@index')->name('admin.ads');
Route::get('/admin/ads/create', 'AdController@create')->name('admin.ads.create');
Route::post('/admin/ads', 'AdController@store')->name('admin.ads.store');
Route::get('/admin/ads/{id}/edit', 'AdController@edit')->name('admin.ads.edit');
Route::patch('/admin/ads/{id}', 'AdController@update')->name('admin.ads.update');
Route::delete('/admin/ads/{id}/delete', 'AdController@destroy')->name('admin.ads.destroy');
Route::post('/admin/ads/{id}/toggle', 'AdController@toggle')->name('admin.ads.toggle');

Route::get('/admin/import-export', 'ImportExportController@index')->name('admin.import-export');
Route::get('/admin/import-export/export/{type}/{format}', 'ImportExportController@export')->name('admin.import-export.export');
Route::post('/admin/import-export/import', 'ImportExportController@import')->name('admin.import-export.import');
Route::post('/admin/import-export/import-json', 'ImportExportController@importJson')->name('admin.import-export.import-json');

// Admin settings
Route::get('/admin/settings', 'SettingsController@index')->name('admin.settings');
Route::post('/admin/settings/profile', 'SettingsController@updateProfile')->name('admin.settings.profile');
Route::post('/admin/settings/password', 'SettingsController@updatePassword')->name('admin.settings.password');
Route::post('/admin/settings/site', 'SettingsController@updateSite')->name('admin.settings.site');
Route::post('/admin/settings/logo-icon', 'SettingsController@updateLogoIcon')->name('admin.settings.logo-icon');
Route::post('/admin/settings/favicon', 'SettingsController@updateFavicon')->name('admin.settings.favicon');
Route::post('/admin/settings/welcome', 'SettingsController@updateWelcome')->name('admin.settings.welcome');
Route::post('/admin/settings/copyright', 'SettingsController@updateCopyright')->name('admin.settings.copyright');
Route::post('/admin/settings/registration', 'SettingsController@updateRegistration')->name('admin.settings.registration');
Route::post('/admin/settings/submit-lyrics', 'SettingsController@updateSubmitLyrics')->name('admin.settings.submit-lyrics');
Route::post('/admin/settings/adsense', 'SettingsController@updateAdsense')->name('admin.settings.adsense');
Route::post('/admin/settings/stats', 'SettingsController@updateStats')->name('admin.settings.stats');
Route::post('/admin/settings/recaptcha', 'SettingsController@updateRecaptcha')->name('admin.settings.recaptcha');

// Admin contacts
Route::get('/admin/contacts', 'ContactController@index')->name('admin.contacts');
Route::get('/admin/contacts/{id}', 'ContactController@view')->name('admin.contacts.view');
Route::delete('/admin/contacts/{id}/delete', 'ContactController@destroy')->name('admin.contacts.destroy');


// Admin pages management
Route::get('/admin/pages', 'PageController@index')->name('admin.pages');
Route::get('/admin/pages/create', 'PageController@create')->name('admin.pages.create');
Route::post('/admin/pages', 'PageController@store')->name('admin.pages.store');
Route::get('/admin/pages/{id}/edit', 'PageController@edit')->name('admin.pages.edit');
Route::patch('/admin/pages/{id}', 'PageController@update')->name('admin.pages.update');
Route::delete('/admin/pages/{id}/delete', 'PageController@destroy')->name('admin.pages.destroy');

// Public pages (privacy, cookie, dmca)
Route::get('/page/{slug}', 'PageController@show')->name('page.show');

// Authentication (affected by registration_enabled setting)
Auth::routes();

// Apply registration check middleware to login/register routes
Route::group(['middleware' => 'registration.check'], function () {
    Route::get('/login', 'Auth\LoginController@showLoginForm')->name('login');
    Route::post('/login', 'Auth\LoginController@login');
    Route::get('/register', 'Auth\RegisterController@showRegistrationForm')->name('register');
    Route::post('/register', 'Auth\RegisterController@register');
});

// Admin login (always accessible - not affected by registration_enabled)
Route::get('/admin/login', 'Auth\LoginController@showLoginForm')->name('admin.login');
Route::post('/admin/login', 'Auth\LoginController@login');

// Purchase page (public)
Route::get('/purchase', 'LicenseController@purchasePage')->name('purchase');
Route::get('/reseller', 'LicenseController@resellerPage')->name('reseller');
Route::post('/reseller/verify', 'LicenseController@verifyResellerLicense')->name('reseller.verify');
Route::get('/reseller/download', 'LicenseController@downloadResellerFile')->name('reseller.download');
Route::post('/purchase/verify', 'LicenseController@verifyLicense')->name('purchase.verify');
Route::get('/purchase/download', 'LicenseController@downloadFile')->name('purchase.download');
Route::post('/api/license/check', 'LicenseController@apiCheck')->name('api.license.check');

// Admin licenses
Route::get('/admin/licenses', 'LicenseController@adminIndex')->name('admin.licenses');
Route::post('/admin/licenses/create', 'LicenseController@adminCreate')->name('admin.licenses.create');
Route::post('/admin/licenses/{id}/toggle', 'LicenseController@adminToggle')->name('admin.licenses.toggle');
Route::post('/admin/licenses/{id}/ban', 'LicenseController@adminBan')->name('admin.licenses.ban');
Route::delete('/admin/licenses/{id}/delete', 'LicenseController@adminDelete')->name('admin.licenses.delete');

// Admin product settings
Route::get('/admin/product-settings', 'LicenseController@adminProductSettings')->name('admin.product-settings');
Route::post('/admin/product-settings/update', 'LicenseController@adminUpdateProduct')->name('admin.product-settings.update');
Route::post('/admin/product-settings/upload', 'LicenseController@adminUploadProduct')->name('admin.product-settings.upload');

// Admin reseller settings
Route::get('/admin/reseller-settings', 'LicenseController@adminResellerSettings')->name('admin.reseller-settings');
Route::post('/admin/reseller-settings/update', 'LicenseController@adminUpdateReseller')->name('admin.reseller-settings.update');
Route::post('/admin/reseller-settings/upload', 'LicenseController@adminUploadResellerProduct')->name('admin.reseller-settings.upload');
Route::get('/admin/certificate/{id}', 'LicenseController@certificate')->name('admin.certificate');
Route::get('/admin/certificate/{id}/print', 'LicenseController@certificatePrint')->name('admin.certificate.print');
Route::get('/admin/certificate-settings', 'LicenseController@certificateSettings')->name('admin.certificate-settings');
Route::post('/admin/certificate-settings/update', 'LicenseController@updateCertificateSettings')->name('admin.certificate-settings.update');

Route::get('songs', function () { return redirect('/'); });
Route::resource('songs','SongController')->except('index');
