package delivery_address_log

import (
	"context"
	"github.com/UpmeshLTD/urus-aio/infrastructure/db/entities"
	"github.com/UpmeshLTD/urus-aio/paid-order/db/gormdb"
	"github.com/UpmeshLTD/urus-aio/paid-order/service/transform"
)

type Service interface {
	GetList(ctx context.Context, params *entities.GetDeliveryAddressLogsParams) ([]*entities.DeliveryAddressLog, error)
	Create(ctx context.Context, deliveryAddress *entities.DeliveryAddress) error
}

type serviceImpl struct {
	db   gormdb.GormDB
	repo Repository
}

func NewService(db gormdb.GormDB, repo Repository) Service {
	return &serviceImpl{
		db:   db,
		repo: repo,
	}
}

func (s serviceImpl) GetList(ctx context.Context, params *entities.GetDeliveryAddressLogsParams) ([]*entities.DeliveryAddressLog, error) {
	return s.repo.GetList(ctx, s.db.DB(), params.CartID, params.SortBy.String()+" "+params.OrderBy.String())
}

func (s serviceImpl) Create(ctx context.Context, deliveryAddress *entities.DeliveryAddress) error {
	return s.repo.Create(ctx, s.db.DB(), transform.DeliveryAddressEntityToDeliveryAddressLogEntity(deliveryAddress))
}
