# frozen_string_literal: true module EuchreCamp module Actions module Admin module Tournaments class Create < EuchreCamp::Action include Deps[repo: 'repositories.events'] def handle(request, response) params = request.params.to_h event_params = { name: params[:name], description: params[:description], event_date: params[:event_date] ? Time.parse(params[:event_date]) : nil, event_type: 'tournament', format: params[:format] || 'single_elim', status: 'planned', max_participants: params[:max_participants]&.to_i } event = repo.create(event_params) response.redirect_to("/admin/tournaments/#{event[:id]}") rescue StandardError => e response.flash[:error] = "Failed to create tournament: #{e.message}" response.redirect_to("/admin/tournaments/new") end end end end end end