require_relative "project_type"

module Devops
  class GenericType

    def self.name
      "generic"
    end

    include ProjectType

    def prepare project
      #TODO: without creating roles
      #project.before_create create_roles
    end

    # def create_roles
    #   lambda {
    #     log = DevopsLogger.logger
    #     log.info "Create roles hook"
    #     #return {roles: nil} if self.multi?
    #     roles = {:new => [], :error => [], :exist => []}
    #     self.deploy_envs.each do |e|
    #       # next if e.use_json_file
    #       role_name = KnifeCommands.role_name(self.id, e.identifier)
    #       chef_env = e.chef_env
    #       if roles[chef_env].nil?
    #         roles[chef_env], r = KnifeCommands.roles(chef_env)
    #         unless r
    #           log.error "Can't get roles list form chef-#{chef_env}: #{roles[chef_env]}"
    #           roles[chef_env] = nil
    #           next
    #         end
    #       end
    #       all_roles = roles[chef_env]
    #       begin
    #         if all_roles.include? role_name
    #           roles[:exist].push role_name
    #           e.run_list << "role[#{role_name}]"
    #         else
    #           KnifeCommands.create_role role_name, self.id, e.identifier, chef_env
    #           roles[:new].push role_name
    #           e.run_list << "role[#{role_name}]"
    #           log.info "Role '#{role_name}' created"
    #         end
    #       rescue => er
    #         roles[:error].push role_name
    #         log.error "Role '#{role_name}' can not be created: #{er.message}"
    #       end
    #     end
    #     {roles: roles}
    #   }
    # end

  end
end
