defaults format: :json do 
  namespace :api do
    namespace :pm do
      resources :dashboards,only: [:index] do
        collection do
          get :todo
          get :my_issues
          get :my_pm_projects
        end
      end
      resources :weekly_issues, only: [:index] do
        collection do
          get :personal
          get :group
          get :group_issues
          get :personal_issues
        end
      end
      resources :dashboards,only: [:index] do 
        collection do 
          get :todo 
          get :my_issues 
          get :my_pm_projects 
          get :my_projects
          get :my_operate_journals
        end
      end
      resources :issues do
        collection do
          patch :batch_update
          delete :batch_destroy
          get :priorities
          get :tags
          get :statues
          get :export 
          post :import
        end
        member do
          get :link_index
          get :parent_issues
          get :link_issues
        end
        resources :issue_links

        resources :journals do
          member do
            get :children_journals
          end
        end
      end
      resources :issue_tags
      resources :sprint_issues, only: [:index] do
        collection do
          get :statistics

          get :burndown_charts
          post :complete
        end
      end
      resources :projects do
        collection do
          get :convert
          get :issues_count
          get :statistics
          get :polyline
        end
      end
      resources :action_runs, only: [:index]
      resources :pipelines, only: [:index]
    end

    namespace :v1 do 

      resources :recruitments, only: [:index] 
      resources :users, only: [:index] do
        collection do 
          post :check_user_id
          post :check_user_login
        end
      end

      resources :sonarqubes ,only: [:index] do
        collection do
          resource :issues
        end
      end

      scope ':owner' do
        resource :users, path: '/', only: [:update, :edit, :destroy] do
          collection do
            get :send_email_vefify_code
            post :check_password 
            post :check_email
            post :check_email_verify_code
            post :check_phone_verify_code
            post :check_user_can_delete
            patch :update_email
            patch :update_phone
          end
        end
        scope module: :organizations do 
          resources :sync_repositories, only: [:create]
          resources :projects, only: [:index]
        end
        scope module: :users do 
          resources :projects, only: [:index]
          resources :feedbacks, only: [:create]
          resources :home_top_settings, only: [:create] do 
            collection do 
              delete :cancel 
            end
          end
          resources :openkylin_sign, only: [:create] do 
            collection do 
              get :competitions
            end
          end
        end

        scope ':repo', constraints: { repo: /[^\/]+/ }  do 
          # projects
          resource :projects, path: '/', only: [:show, :update, :edit] do 
            collection do 
              get :compare
              get :blame

            end
          end
          resource :sonarqubes, only: [:index] do
            collection do
              get :issues_search
              get :ce_component
              get :sources_issue_snippet
              get :rules_show
              get :measures_search_history
              get :measures_component

              post :sonar_initialize
              post :insert_file
              get :doxygen_url
              get :analyze_doxygen

            end
          end

          resources :issues, param: :index, except: [:new, :edit] do 
            collection do 
              patch :batch_update
              delete :batch_destroy
              post :pm_create
            end

            member do 
              get :show_by_id
              resources :journals, module: :issues, only: [:index, :create, :update, :destroy] do 
                member do
                  get :children_journals 
                end
              end
            end
          end
          scope module: :issues do
            resources :issue_tags, except: [:new, :edit] do
            collection do
              get :pm_index
            end
          end
            resources :milestones, except: [:new, :edit]
            resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' do
              collection do
                get :pm_index
              end
            end
            resources :issue_authors, only: [:index], controller: '/api/v1/issues/authors'
            resources :issue_assigners, only: [:index], controller: '/api/v1/issues/assigners'
            resources :issue_priorities, only: [:index] do
              collection do
                get :pm_index
              end
            end
          end

          # projects文件夹下的
          scope module: :projects do 
            resources :oss_health_measuring, only: [:index] do
              collection do
                get :can_get
                get :keyid
              end
            end
            resources :portrait, only: [:index] do 
              collection do 
                get :community_impact
                get :project_maturity
                get :project_health
                get :team_impact
                get :develop_activity
              end
            end
            resources :sync_repositories, only: [:create, :index] do 
              collection do 
                post :update_info
                post :sync
                get :branches
                post :change_enable
                post :unbind
                get :history
                post :create_branch
              end
            end
            resource :dataset, only: [:create, :update, :show]
            resources :actions, module: 'actions' do
              collection do 
                get :new_index
                post :disable
                post :enable
                resources :runs, only: [:index, :create] do 
                  post '/jobs/:job', to: 'runs#job_show'
                  post '/rerun', to: 'runs#rerun'
                  post '/cancel', to: 'runs#cancel'
                  post '/jobs/:job/rerun', to: 'runs#job_rerun'
                  get '/jobs/:job/logs', to: 'runs#job_logs'
                end
              end
            end
            resources :sca, only: [:index,:create]
            resources :pipelines do
              post :build_yaml, on: :collection
              post :save_yaml, on: :collection
              post :upload_results, on: :collection
              get :run_results, on: :collection
              get :test_yaml, on: :collection
            end
            resources :pulls, module: 'pulls' do
              member do
                get :files
                post :reopen
              end
              resources :versions, only: [:index] do
                member do 
                  get :diff
                end
              end
              resources :journals, except: [:show, :edit]
              resources :reviews, only: [:index, :create] 
            end
            resources :collaborators, only: [:index]
            resources :release_versions
            resources :webhooks do 
              member do 
                post :tests 
                get :hooktasks 
              end
            end
            resources :branches, param: :name, only:[:index, :create, :destroy] do 
              collection do 
                get :gitee 
                get :github
                get :all
                post :restore
                patch :update_default_branch
              end
            end
            match 'branches/*name', to: "branches#destroy", via: :all

            resources :tags, param: :name, only: [:index, :show, :destroy]
            delete 'tags/*name', to: "tags#destroy", via: :all
            get 'tags/*name', to: "tags#show", via: :all
            get '/compare/:base...:head/files' => 'compare#files', :constraints => { base: /.+/, head: /.+/ }

            resources :commits, only: [:index] do 
              collection do 
                get :recent
              end
            end
            resources :code_stats, only: [:index]
            resources :contributors, only: [:index] do 
              collection do 
                get :stat
              end
            end
            get '/commits/:sha/diff', to: 'commits#diff'
            get '/commits/:sha/files', to: 'commits#files'
            get '/git/blobs/:sha', to: 'git#blobs'
            get '/git/trees/:sha', to: 'git#trees'

            resources :contents, only: [:index] do 
              collection do 
                post :batch
              end
            end
          end
        end

      end

      resources :projects, only: [:index]
      resources :project_topics, only: [:index, :create, :destroy]
      resources :project_datasets, only: [:index]
      resources :gitlink_competition_applies, only: [:create]

    end
  end
end