package accntcli

import (
	"context"
	"encoding/json"
	"errors"

	"mstore/app/handler"
	"mstore/app/imageoper"
)

func (cli *Client) ServiceHello(ctx context.Context, host string) (bool, error) {
	var res bool
	var err error

	params := imageoper.SendHelloParams{}
	reqdata, err := json.Marshal(params)
	if err != nil {
		return res, err
	}
	resdata, err := cli.doHTTPCall(ctx, host, "service", "hello", reqdata)
	if err != nil {
		return res, err
	}
	response := handler.Response[imageoper.SendHelloResult]{}
	err = json.Unmarshal(resdata, &response)
	if err != nil {
		return res, err
	}
	if response.Error {
		err = errors.New(response.Message)
		return res, err
	}
	res = response.Result.Alive
	return res, err
}
