<?php


namespace App\Http\Historico;


// Modelos
use App\Log;


// Controladores
use App\Http\Controllers\AreaController;


// Historico
use App\Http\Historico\Historico;


class AreaHistorico extends Historico {    

    public function store($accion, $obj){

        $this->SetInformacionLog($accion, $obj);
        
        switch($this->accion){
            case "store":
                $nom_area = $this->req->nombre;
                $this->tableLog->titulo = "Registro";
                $this->tableLog->descripcion = "nombre: $nom_area";
                break;

            case "update":
                                
                $nom_area = AreaController::listItem($this->req->id)->nom_area;

                switch($this->req->campo){
                    case "nombre":
                        $new_nom_area = $this->req->nombre;
                        $this->tableLog->titulo = "Modificación de nombre";
                        $this->tableLog->descripcion = "Para el área $nom_area se actualiza a: $new_nom_area";
                    break;
                }
                break;

            case "destroy":
                $nom_area = AreaController::listItem($this->req->id)->nom_area;
                $this->tableLog->titulo = "Eliminación";
                $this->tableLog->descripcion = "Área: $nom_area";
                break;

            case "status":
                $nom_area = AreaController::listItem($this->req->id)->nom_area;
                $statusNow = AreaController::listItem($this->req->id)->estado;
                if($statusNow == 1){
                    $this->tableLog->titulo = "Inactivación";
                    $this->tableLog->descripcion = "Área: $nom_area";
                } else {
                    $this->tableLog->titulo = "Reactivación";
                    $this->tableLog->descripcion = "Área: $nom_area";
                }
                break;
        }

        $this->tableLog->tabla = 'Area';
        $this->tableLog->save();
    }
}