class Admin::Legacy::Student::Students::Indiana::SummerReleaseController < ApplicationController
  def index
    dir = "#{current_school.indiana_environment_service}::SummerReleaseService"
    resp = dir.constantize.call(
      current_school_year.id,
      student.id,
      :show
    )
    render_success :ok, json: { released: resp.present? }
  end

  def create
    dir = "#{current_school.indiana_environment_service}::SummerReleaseService"
    resp = dir.constantize.call(
      current_school_year.id,
      student.id,
      :post,
      params[:exit_type]
    )
    if resp
      render_success :ok, json: { records: resp }
    else
      render_error :unprocessable_entity
    end
  end

  private
    def student
      @student ||= current_school.students.find_by(id: params[:student_id])
    end
end
