package client

import (
	"sync/atomic"

	crc "git.loafle.net/commons/rpc-go/client"
	csc "git.loafle.net/commons/server-go/client"
)

type ClientHandler interface {
	crc.ClientHandler
}

type ClientHandlers struct {
	crc.ClientHandlers

	validated atomic.Value
}

func (ch *ClientHandlers) Init(clientCtx csc.ClientCtx) error {
	if err := ch.ClientHandlers.Init(clientCtx); nil != err {
		return err
	}

	return nil
}

func (ch *ClientHandlers) OnStart(clientCtx csc.ClientCtx) error {
	if err := ch.ClientHandlers.OnStart(clientCtx); nil != err {
		return err
	}

	return nil
}

func (ch *ClientHandlers) OnStop(clientCtx csc.ClientCtx) {

	ch.ClientHandlers.OnStop(clientCtx)
}

func (ch *ClientHandlers) Destroy(clientCtx csc.ClientCtx) {

	ch.ClientHandlers.Destroy(clientCtx)
}

func (ch *ClientHandlers) Validate() error {
	if nil != ch.validated.Load() {
		return nil
	}
	ch.validated.Store(true)

	if err := ch.ClientHandlers.Validate(); nil != err {
		return err
	}

	return nil
}
