class Settings::AccountsController < ApplicationController
  load_and_authorize_resource except: [:create]
  before_action :set_account, only: [:show, :edit, :update, :destroy]

  # GET /settings/accounts
  # GET /settings/accounts.json
  def index
    @settings_accounts = Account.all
  end

  # GET /settings/accounts/1
  # GET /settings/accounts/1.json
  def show
  end

  # GET /settings/accounts/new
  def new
    @settings_account = Account.new
  end

  # GET /settings/accounts/1/edit
  def edit
  end

  # POST /settings/accounts
  # POST /settings/accounts.json
  def create
    @settings_account = Account.new(account_params)
    respond_to do |format|
      if @settings_account.save!
        format.html { redirect_to settings_accounts_url, notice: 'Account was successfully created.' }
        format.json { render :index, status: :created, location: @settings_account }
      else
        format.html { render :new }
        format.json { render json: settings_accounts_url.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /settings/accounts/1
  # PATCH/PUT /settings/accounts/1.json
  def update
    respond_to do |format|
      if @settings_account.update(account_params)
        format.html { redirect_to settings_accounts_url, notice: 'Account was successfully updated.' }
        format.json { render :index, status: :ok, location: @settings_account }
      else
        format.html { render :edit }
        format.json { render json: settings_accounts_url.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /settings/accounts/1
  # DELETE /settings/accounts/1.json
  def destroy
    @settings_account.destroy
    respond_to do |format|
      format.html { redirect_to settings_accounts_url, notice: 'Account was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_account
      @settings_account = Account.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def account_params
      params.require(:account).permit(:title, :account_type,:discount,:point,:bonus,:rebate)
    end
end
