class MetapursesController < ApplicationController
  before_action :set_metapurse, only: %i[ show edit update destroy data ]

  # GET /metapurses or /metapurses.json
  def index
   authorize @metapurses = policy_scope(Metapurse)
  end

  # GET /metapurses/1 or /metapurses/1.json
  def show
    authorize @metapurse
  end

  def data
    authorize @metapurse
  end


  # GET /metapurses/new
  def new
    authorize @metapurse = current_user.metapurses.new
    @metapurse.data = "ryjl3-tyaaa-aaaaa-aaaba-cai 100 ICP
iozql-7iaaa-aaaah-advvq-cai 880 TENDIES
whdfs-saaaa-aaaao-awh4a-cai 240 NEED
ss2fx-dyaaa-aaaar-qacoq-cai 0.1 ckETH
nwd3n-qaaaa-aaaak-afmda-cai 192.92 INSANE
eayyd-iiaaa-aaaah-adtea-cai 5678.1234 iDoge
rh2pm-ryaaa-aaaan-qeniq-cai 69420.98 Windoge98 EXE
7tx3o-zyaaa-aaaak-aes6q-cai 1337456899999 DOGMI
wnnwu-4iaaa-aaaar-qacxq-cai 420690000 SKIBIDI
67mu5-maaaa-aaaar-qadca-cai 360 MCS
kz5t3-pyaaa-aaaap-ab2qq-cai 5000000 iVishnu"
  end

  # GET /metapurses/1/edit
  def edit
    authorize @metapurse
  end

  # POST /metapurses or /metapurses.json
  def create
    authorize @metapurse = Metapurse.new(metapurse_params)

    respond_to do |format|
      if @metapurse.save
        format.html { redirect_to metapurse_url(@metapurse), notice: "Metapurse was successfully created." }
        format.json { render :show, status: :created, location: @metapurse }
      else
        format.html { render :new, status: :unprocessable_entity }
        format.json { render json: @metapurse.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /metapurses/1 or /metapurses/1.json
  def update
    authorize @metapurse
    respond_to do |format|
      if @metapurse.update(metapurse_params)
        format.html { redirect_to metapurse_url(@metapurse), notice: "Metapurse was successfully updated." }
        format.json { render :show, status: :ok, location: @metapurse }
      else
        format.html { render :edit, status: :unprocessable_entity }
        format.json { render json: @metapurse.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /metapurses/1 or /metapurses/1.json
  def destroy
    authorize @metapurse
    @metapurse.destroy!

    respond_to do |format|
      format.html { redirect_to metapurses_url, notice: "Metapurse was successfully destroyed." }
      format.json { head :no_content }
    end
  end

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

    # Only allow a list of trusted parameters through.
    def metapurse_params
      params.require(:metapurse).permit(:name, :data, :user_id, :is_private)
    end
end
