package benefactoraddressservice

import (
	"context"

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

func (s Service) Update(ctx context.Context, req param.UpdateAddressRequest) error {
	const op = "benefactoraddressservice.Update"

	err := s.repo.UpdateAddress(ctx, entity.Address{
		ID:           req.ID,
		PostalCode:   req.PostalCode,
		Address:      req.Address,
		Name:         req.Name,
		Lat:          req.Lat,
		Lon:          req.Lon,
		CityID:       req.CityID,
		BenefactorID: req.BenefactorID,
	})
	if err != nil {

		return richerror.New(op).WithErr(err)
	}

	return nil
}
