<?php

namespace App\Http\Controllers;

use App\Models\Plantilla;
use Illuminate\Http\Request;

class PlantillaController extends Controller
{
    // public function index(Request $request) {}
    // public function show($id) {}
    public function store(Request $request) {
        $model = new Plantilla;
        $model->nombre = $request->input('nombre');
        $model->configuracion = $request->input('configuracion');
        $model->save();

        $data = [
            'element' => $model,
            'success' => 'Registrado'
        ];
        return response()->json($data, 200);
    }
    public function update(Request $request, $id) {
        $model = Plantilla::find($id);
        if (!$model) {
            return response()->json('No se encontro el registro', 409);
        }
        $model->nombre = $request->input('nombre');
        $model->configuracion = $request->input('configuracion');
        $model->save();

        $data = [
            'element' => $model,
            'success' => 'Actualizado'
        ];
        return response()->json($data, 200);
    }
    // public function destroy($id) {}
}
