<?php

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

class TempoArrumarController extends Controller
{
    public function create (Request $request) {
        
        $tempoArrumar= new TempoArrumar();
        $verificarTempo=TempoArrumar::where('ano',$request->ano)->where('mes',$request->mes)->first();
        if($verificarTempo){
            return 0;
        }else{
            
            $tempoArrumar->tempo=$request->numero;
            $tempoArrumar->ano=$request->ano;
            $tempoArrumar->mes=$request->mes;
            $tempoArrumar->usuario_id=Auth::id();
            $tempoArrumar->save();
            
            return 1;
        }
    }
    public function remove (Request $request) {
        $tempoArrumar= new TempoArrumar();
        
    }
    public function update (Request $request) {
        
        
        $tempoArrumar=TempoArrumar::where('id',$request->id)->first();
        
        if($tempoArrumar){
            $verificarTempo=TempoArrumar::where('tempo',$request->numero)->where('ano',$request->ano)->where('mes',$request->mes)->first();
            if($verificarTempo){
                return 0;
            }else{
                $tempoArrumar->tempo=$request->numero;
                $tempoArrumar->ano=$request->ano;
                $tempoArrumar->mes=$request->mes;
                $tempoArrumar->usuario_id=Auth::id();
                $tempoArrumar->save();
                
                return 1;
            }
        }else{
            return 0;
        }
        
    }
    public function listar (Request $request) {
        $tempoArrumar= new TempoArrumar();
        
    }
}
