class Internal::Paya::ContactsController < Internal::Paya::Controller
  def index
    render_success :ok, json: contact_service(:show)
  end

  def create
    response = contact_service(:create)

    if response['errors']
      render_error :unprocessably_entity, json: response
    else
      render_success :ok, json: response
    end
  end

  private
    def family
      @family ||= current_school.families.find_by(id: params[:family_id])
    end

    def contact
      @contact ||= family.contacts.find_by(id: params[:contact_id])
    end

    def contact_service(method)
      Paya::ContactService.call(current_school, method, contact, family)
    end
end
