package patchsvc

import (
	"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
	objectwriter "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/common/writer"
	getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
)

// Service implements Put operation of Object service v2.
type Service struct {
	*objectwriter.Config

	getSvc *getsvc.Service
}

// NewService constructs Service instance from provided options.
//
// Patch service can use the same objectwriter.Config initializied by Put service.
func NewService(cfg *objectwriter.Config,
	getSvc *getsvc.Service,
) *Service {
	return &Service{
		Config: cfg,

		getSvc: getSvc,
	}
}

// Patch calls internal service and returns v2 object streamer.
func (s *Service) Patch() (object.PatchObjectStream, error) {
	nodeKey, err := s.Config.KeyStorage.GetKey(nil)
	if err != nil {
		return nil, err
	}

	return &Streamer{
		Config:       s.Config,
		getSvc:       s.getSvc,
		localNodeKey: nodeKey,
	}, nil
}