module Licitacao
  class AcoesDoEtpController < ApplicationController
    before_action :set_etp, only: [:new, :create, :retorna_modelo, :index, :show]
    before_action :set_acao_do_etp, only: [:show, :edit, :update, :destroy]
    before_action :disponibiliza_dependencias, only: [:new, :create, :edit, :update, :destroy]
    def index
      @acoes_do_etp = @etp.acoes_do_etp
    end
    
    def new
      @acao_do_etp = @etp.acoes_do_etp.new
    end
    
    def create
      @acao_do_etp = @etp.acoes_do_etp.new(acao_do_etp_params)
      if @acao_do_etp.save
        redirect_to licitacao_etp_path(@etp), notice: 'Ação criada com sucesso.'
      else
        render :new
      end
    end    
    
    def show
    end
    
    def edit
    end
    
    def update
      if @acao_do_etp.update(acao_do_etp_params)
        redirect_to licitacao_etp_path(@etp), notice: 'Ação atualizada com sucesso.'
      else
        render :edit
      end
    end
    
    def destroy
      @acao_do_etp.destroy
      redirect_to licitacao_acoes_do_etp_path(@etp), notice: 'Ação excluída com sucesso.'
    end
    
    private
    
    def set_etp
      @etp = Licitacao::Etp.find(params[:etp_id])
    end
    
    def set_acao_do_etp
      @acao_do_etp = Licitacao::AcaoDoEtp.find(params[:id])
    end
    
    def disponibiliza_dependencias
      @acoes = Pca::Acao.all
    end  
    
    def acao_do_etp_params
      params.require(:acao_do_etp).permit(:acao_id)
    end
  end
end