module Licitacao
class VistosDeDocumentosDoProcessoController < ApplicationController
	include ControllerConcern
	before_action :authenticate_usuario!
	before_action :autoriza_usuario!
	before_action :set_visto_de_documento_do_processo, only: [:edit, :update, :destroy]
	before_action :set_documento_do_processo, only: [:destroy, :new, :create]

	# GET /licitacao/vistos_de_documentos_do_processo/new
	def new
		@visto_de_documento_do_processo = Licitacao::VistoDeDocumentoDoProcesso.new
	end

	# GET /licitacao/vistos_de_documentos_do_processo/1/edit
	def edit
	end

	# POST /licitacao/vistos_de_documentos_do_processo
	def create
		@visto_de_documento_do_processo = Licitacao::VistoDeDocumentoDoProcesso.new(visto_de_documento_do_processo_params)

		if @visto_de_documento_do_processo.save
			redirect_to @documento_do_processo, notice: 'Visto de documento do processo foi criado(a) com sucesso.'
		else
			render :new
		end
	end

	# PATCH/PUT /licitacao/vistos_de_documentos_do_processo/1
	def update
		if @visto_de_documento_do_processo.update( visto_de_documento_do_processo_params )
			redirect_to @visto_de_documento_do_processo.documento_do_processo, notice: 'Visto de documento do processo foi atualizado(a) com sucesso.'
		else
			render :edit
		end
	end

	# DELETE /licitacao/vistos_de_documentos_do_processo/1
	def destroy
		mensagem = apaga_e_retorna_mensagem(@visto_de_documento_do_processo)
		redirect_to @documento_do_processo, notice: 'Visto de documento apagado com sucesso.'
	end

	private
	def set_visto_de_documento_do_processo
		@visto_de_documento_do_processo = Licitacao::VistoDeDocumentoDoProcesso.find( params[:id] )
	end

	def set_documento_do_processo
		id_documento = params[:documento_do_processo_id].present? ? params[:documento_do_processo_id] : params[:licitacao_visto_de_documento_do_processo][:documento_do_processo_id]
		@documento_do_processo = Licitacao::DocumentoDoProcesso.find( id_documento )
	end

	# Permite apenas os parâmetros específicos
	def visto_de_documento_do_processo_params
		params.require(:licitacao_visto_de_documento_do_processo).permit(:documento_do_processo_id, :aprovado, :justificativa)
	end
end
end
