func (h *Handler) ChangeChannelStatus(tkn, channel, action string) error {
	logger := h.logger.Add("method", "ChangeChannelStatus",
		"channel", channel, "action", action, "userRole", h.userRole)

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return ErrAccessDenied
	}

	condition := fmt.Sprintf("WHERE id = %s ", h.db.Placeholder(1))

	isAgent := h.userRole == data.RoleAgent

	if !isAgent {
		condition = fmt.Sprintf("%s AND %s",
			condition, clientChannelsCondition)
	}

	items, err := h.selectAllFrom(
		logger, data.ChannelTable, condition, channel)
	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	if len(items) != 1 {
		logger.Error(ErrChannelNotFound.Error())
		return ErrChannelNotFound
	}

	switch action {
	case ChannelPauseAction:
		_, err = h.processor.SuspendChannel(
			channel, data.JobUser, isAgent)
	case ChannelResumeAction:
		_, err = h.processor.ActivateChannel(
			channel, data.JobUser, isAgent)
	case ChannelTerminateAction:
		_, err = h.processor.TerminateChannel(
			channel, data.JobUser, isAgent)
	case ChannelCloseAction:
		if isAgent {
			logger.Error(ErrNotAllowedForAgent.Error())
			return ErrNotAllowedForAgent
		}
		if err := h.createPreUncooperativeCloseRequest(
			channel, logger); err != nil {
			return ErrInternal
		}
	default:
		logger.Warn(ErrBadAction.Error())
		return ErrBadAction
	}

	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	return nil
}
func (h *Handler) ChangeChannelStatus(tkn, channel, action string) error {
	logger := h.logger.Add("method", "ChangeChannelStatus",
		"channel", channel, "action", action, "userRole", h.userRole)

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return ErrAccessDenied
	}

	condition := fmt.Sprintf("WHERE id = %s ", h.db.Placeholder(1))

	isAgent := h.userRole == data.RoleAgent

	if !isAgent {
		condition = fmt.Sprintf("%s AND %s",
			condition, clientChannelsCondition)
	}

	items, err := h.selectAllFrom(
		logger, data.ChannelTable, condition, channel)
	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	if len(items) != 1 {
		logger.Error(ErrChannelNotFound.Error())
		return ErrChannelNotFound
	}

	switch action {
	case ChannelPauseAction:
		_, err = h.processor.SuspendChannel(
			channel, data.JobUser, isAgent)
	case ChannelResumeAction:
		_, err = h.processor.ActivateChannel(
			channel, data.JobUser, isAgent)
	case ChannelTerminateAction:
		_, err = h.processor.TerminateChannel(
			channel, data.JobUser, isAgent)
	case ChannelCloseAction:
		if isAgent {
			logger.Error(ErrNotAllowedForAgent.Error())
			return ErrNotAllowedForAgent
		}
		if err := h.createPreUncooperativeCloseRequest(
			channel, logger); err != nil {
			return ErrInternal
		}
	default:
		logger.Warn(ErrBadAction.Error())
		return ErrBadAction
	}

	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	return nil
}
// ChangeChannelStatus updates channel state.