<?php

namespace App\Http\Controllers;

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

class EmpresaController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     */
    public function show(Empresa $empresa)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(Empresa $empresa)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, Empresa $empresa)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(Empresa $empresa)
    {
        //
    }

    public function storeAjax(Request $request)
    {
        $request->validate([
            'nit' => 'required',
            'nombre' => 'required',
            'direccion_empresa' => 'required',
            'correo_empresa' => 'required|email',
            'contacto_empresa' => 'required',
            'registro_seprec' => 'required',
            'representante_legal' => 'required',
        ]);

        $empresa = Empresa::create($request->all());

        return response()->json([
            'success' => true,
            'empresa' => $empresa,
        ]);
    }

    public function getSelectOptions()
    {
        $empresas = Empresa::all();
        return response()->json($empresas);
    }
}
