# frozen_string_literal: true

namespace :analytics do
  root to: 'analytics#index'

  resource :productivity_analytics, only: :show, constraints: -> (req) { Feature.disabled?(:group_level_productivity_analytics) && Gitlab::Analytics.productivity_analytics_enabled? }

  constraints(-> (req) { Gitlab::Analytics.cycle_analytics_enabled? }) do
    resource :cycle_analytics, only: :show, path: 'value_stream_analytics'
    scope module: :cycle_analytics, as: 'cycle_analytics', path: 'value_stream_analytics' do
      resources :stages, only: [:index, :create, :update, :destroy] do
        member do
          get :duration_chart
          get :median
          get :records
        end
      end
      resource :summary, controller: :summary, only: :show
    end
    get '/cycle_analytics', to: redirect('-/analytics/value_stream_analytics')
  end

  constraints(::Constraints::FeatureConstrainer.new(Gitlab::Analytics::TASKS_BY_TYPE_CHART_FEATURE_FLAG)) do
    scope :type_of_work do
      resource :tasks_by_type, controller: :tasks_by_type, only: :show do
        get :top_labels
      end
    end
  end
end
