package adminseederservice

import (
	"context"

	"git.gocasts.ir/ebhomengo/niki/entity"
	richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)

func (s Service) AssignReceiverAgentKindBox(ctx context.Context, agentId uint) (entity.KindBox, error) {
	const op = "adminseederservice.AssignReceiverAgentKindBox"

	kindBox, kErr := s.AddKindBox(ctx, agentId, entity.KindBoxReadyToReturnStatus)
	if kErr != nil {
		return entity.KindBox{}, richerror.New(op).WithErr(kErr).WithKind(richerror.KindUnexpected)
	}

	aErr := s.kindBoxRepo.AssignReceiverAgent(ctx, entity.KindBox{
		ID:              kindBox.ID,
		ReceiverAgentID: agentId,
	})
	if aErr != nil {
		return entity.KindBox{}, richerror.New(op).WithErr(aErr).WithKind(richerror.KindUnexpected)
	}

	return kindBox, nil
}
