<?php

namespace App\Http\Controllers;
use App\Models\AuditoriaInterna;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;

class AuditoriaInternaController extends Controller
{
    public function create (Request $request) {
        $auditInt= new AuditoriaInterna();
        $verificaAudit=AuditoriaInterna::where('ano',$request->ano)->where('mes',$request->mes)->first();
        if($verificaAudit){
            return 0;
        }else{
            
            $auditInt->auditorias=$request->numero;
            $auditInt->ano=$request->ano;
            $auditInt->mes=$request->mes;
            $auditInt->usuario_id=Auth::id();
            $auditInt->save();
            
            return 1;
        }
    }
    public function remove (Request $request) {
        
    }
    public function update (Request $request) {
        $auditInt=AuditoriaInterna::where('id',$request->id)->first();
        
        if($auditInt){
            $verificaAudit=AuditoriaInterna::where('auditorias',$request->numero)->where('ano',$request->ano)->where('mes',$request->mes)->first();
            if($verificaAudit){
                return 0;
            }else{
                $auditInt->auditorias=$request->numero;
                $auditInt->ano=$request->ano;
                $auditInt->mes=$request->mes;
                $auditInt->usuario_id=Auth::id();
                $auditInt->save();
                
                return 1;
            }
        }else{
            return 0;
        }
        
    }
    public function listar (Request $request) {
        
    }
}
