<?php

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

class ReclamacaoController extends Controller
{
    public function create (Request $request) {
        $reclamacao= new Reclamacao();
        $verificaReclamacao=Reclamacao::where('ano',$request->ano)->where('mes',$request->mes)->first();
        if($verificaReclamacao){
            return 0;
        }else{
            
            $reclamacao->reclamacoes=$request->numero;
            $reclamacao->ano=$request->ano;
            $reclamacao->mes=$request->mes;
            $reclamacao->usuario_id=Auth::id();
            $reclamacao->save();
            
            return 1;
        }
        
    }
    public function remove (Request $request) {
        
    }
    public function update (Request $request) {
         $reclamacao=Reclamacao::where('id',$request->id)->first();
        
        if($reclamacao){
            $verificaReclamacao=Reclamacao::where('reclamacoes',$request->numero)->where('ano',$request->ano)->where('mes',$request->mes)->first();
            if($verificaReclamacao){
                return 0;
            }else{
                $reclamacao->reclamacoes=$request->numero;
                $reclamacao->ano=$request->ano;
                $reclamacao->mes=$request->mes;
                $reclamacao->usuario_id=Auth::id();
                $reclamacao->save();
                
                return 1;
            }
        }else{
            return 0;
        }
    }
    public function listar (Request $request) {
        
    }
}
