require 'swagger/blocks'

require_relative 'devops_error'
require_relative 'devops_response'

module Devops
  module API3
    module Docs
      class ChefRoutes

        include Swagger::Blocks

        swagger_path "/chef/bootstrap_templates" do
          operation :get do
            key :description, 'Get list of available bootstrap templates'
            key :operationId, 'getBootstrapTemplates'
            key :tags, [
              'chef'
            ]
            response 200 do
              key :description, 'List of available bootstrap templates'
              schema do
                key :type, :array
                items do
                  key :type, :string
                end
              end
            end
            response :default do
              key :description, 'error'
              schema do
                key :'$ref', :DevopsError
              end
            end
          end
        end

        swagger_path "/chef/nodes" do
          operation :get do
            key :description, 'Get chef nodeslist'
            key :operationId, 'getChefNodes'
            key :tags, [
              'chef'
            ]
            response 200 do
              key :description, 'Chef nodes list'
              schema do
                key :type, :array
                items do
                  key :type, :string
                end
              end
            end
            response :default do
              key :description, 'error'
              schema do
                key :'$ref', :DevopsError
              end
            end
          end
        end

        swagger_path "/chef/tags/{cm_name}" do
          operation :get do
            key :description, 'Get node tags'
            key :operationId, 'getNodeTags'
            key :tags, [
              'chef'
            ]
            parameter do
              key :name, :cm_name
              key :in, :path
              key :description, 'Chef node name'
              key :required, true
              key :type, :string
            end
            response 200 do
              key :description, 'Node tags list'
              schema do
                key :type, :array
                items do
                  key :type, :string
                end
              end
            end
            response :default do
              key :description, 'error'
              schema do
                key :'$ref', :DevopsError
              end
            end
          end
        end

        swagger_path "/chef/tags/{cm_name}/set" do
          operation :post do
            key :description, 'Set node tags'
            key :operationId, 'setNodeTags'
            key :tags, [
              'chef'
            ]
            parameter do
              key :name, :cm_name
              key :in, :path
              key :description, 'Chef node name'
              key :required, true
              key :type, :string
            end
            parameter do
              key :name, :tags
              key :in, :body
              key :description, 'Tags to set to node'
              key :required, true
              schema do
                key :'$ref', :PetInput
              end
            end
            response 200 do
              key :description, 'Node tags list'
              schema do
                key :'$ref', :TagsResponse
              end
            end
            response :default do
              key :description, 'error'
              schema do
                key :'$ref', :DevopsError
              end
            end
          end
        end

        swagger_path "/chef/tags/{cm_name}/unset" do
          operation :post do
            key :description, 'Unset node tags'
            key :operationId, 'unsetNodeTags'
            key :tags, [
              'chef'
            ]
            parameter do
              key :name, :cm_name
              key :in, :path
              key :description, 'Chef node name'
              key :required, true
              key :type, :string
            end
            parameter do
              key :name, :tags
              key :in, :body
              key :description, 'Tags to unset from node'
              key :required, true
              schema do
                key :'$ref', :PetInput
              end
            end
            response 200 do
              key :description, 'Node tags list'
              schema do
                key :'$ref', :TagsResponse
              end
            end
            response :default do
              key :description, 'error'
              schema do
                key :'$ref', :DevopsError
              end
            end
          end
        end

        swagger_schema :TagsResponse do
          allOf do
            schema do
              key :'$ref', :DevopsResponse
            end
            schema do
              property :tags do
                key :type, :array
                items do
                  key :type, :string
                end
              end
            end
          end
        end

      end
    end
  end
end
