package responsibility_chain

import "strconv"

type Handle interface {
	Handle(handleId int) string
}

type handle struct {
	name     string
	next     *handle
	handleId int
}

func NewHandle(name string, next *handle, handleId int) *handle {
	return &handle{name: name, next: next, handleId: handleId}
}

func (h *handle) Handle(handleId int) string {
	if h.handleId == handleId {
		return h.name + " 操作 " + strconv.Itoa(handleId)
	}
	if h.next == nil {
		return ""
	}
	return h.next.Handle(handleId)
}