package agentkindboxservice

import (
	"context"

	param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
	richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)

func (s Service) Return(ctx context.Context, req param.ReturnKindBoxRequest) (param.ReturnKindBoxResponse, error) {
	const op = "agentkindboxservice.Return"
	if fieldErrors, vErr := s.vld.ValidateReturn(ctx, req); vErr != nil {
		return param.ReturnKindBoxResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
	}

	rErr := s.repo.ReturnKindBox(ctx, req.KindBoxID, req.SerialNumber)
	if rErr != nil {
		return param.ReturnKindBoxResponse{}, richerror.New(op).WithErr(rErr)
	}

	return param.ReturnKindBoxResponse{}, nil
}
