<?php

use Illuminate\Support\Facades\Route;
use Mtc\Plugins\BlockManager\Http\Controllers\BlockManagerController;
use Mtc\Plugins\BlockManager\Http\Controllers\BlockShipController;
use Mtc\Plugins\BlockManager\Http\Controllers\DesignTokenController;
use Mtc\Plugins\BlockManager\Http\Controllers\ElementCatalogueController;
use Mtc\Plugins\BlockManager\Http\Controllers\PropertySchemaController;
use Mtc\Plugins\BlockManager\Http\Controllers\VariantDesignerController;
use Mtc\Plugins\BlockManager\Http\Controllers\VariantPublishController;

Route::get('/api/block-manager/ping', function () {
    return response()->json(['status' => 'ok']);
});

Route::get('/api/block-manager/elements', [ElementCatalogueController::class, 'index']);
Route::get('/api/block-manager/tokens', [DesignTokenController::class, 'index']);
Route::get('/api/block-manager/property-schema', [PropertySchemaController::class, 'index']);

// Composed-block CRUD. {id} is constrained to numbers so it doesn't shadow /ping or /elements.
Route::get('/api/block-manager', [BlockManagerController::class, 'index']);
Route::post('/api/block-manager', [BlockManagerController::class, 'store']);
// Live composer-canvas preview (string segment — declared before /{id} numeric routes).
Route::post('/api/block-manager/preview', [BlockManagerController::class, 'preview']);
Route::get('/api/block-manager/{id}', [BlockManagerController::class, 'show'])->whereNumber('id');
Route::put('/api/block-manager/{id}', [BlockManagerController::class, 'update'])->whereNumber('id');
Route::delete('/api/block-manager/{id}', [BlockManagerController::class, 'destroy'])->whereNumber('id');
Route::post('/api/block-manager/{id}/duplicate', [BlockManagerController::class, 'duplicate'])->whereNumber('id');
Route::post('/api/block-manager/{id}/ship', [BlockShipController::class, 'ship'])->whereNumber('id');
Route::get('/api/block-manager/{id}/ship/preview', [BlockShipController::class, 'preview'])->whereNumber('id');

// Variant draft CRUD (Designer working state).
Route::get('/api/block-manager/variants', [VariantDesignerController::class, 'index']);
Route::post('/api/block-manager/variants', [VariantDesignerController::class, 'store']);
Route::post('/api/block-manager/variants/import-existing', [VariantDesignerController::class, 'importExisting']);
Route::get('/api/block-manager/variants/{id}', [VariantDesignerController::class, 'show'])->whereNumber('id');
Route::put('/api/block-manager/variants/{id}', [VariantDesignerController::class, 'update'])->whereNumber('id');
Route::delete('/api/block-manager/variants/{id}', [VariantDesignerController::class, 'destroy'])->whereNumber('id');
Route::post('/api/block-manager/variants/{id}/preview', [VariantDesignerController::class, 'preview'])->whereNumber('id');
Route::get('/api/block-manager/variants/{id}/conflict', [VariantDesignerController::class, 'conflict'])->whereNumber('id');
Route::post('/api/block-manager/variants/{id}/publish', [VariantPublishController::class, 'publish'])->whereNumber('id');
