package adssvc

import (
	"fmt"
	adsdomain "legalgo-BE-go/internal/domain/ads"
	"strings"

	"github.com/google/uuid"
)

func (i *impl) Create(spec adsdomain.AdsReq) error {
	if !(strings.HasPrefix(spec.Image, "http")) {
		return fmt.Errorf("image url is not started with http")
	}

	if !(strings.HasPrefix(spec.URL, "http")) {
		return fmt.Errorf("url is not started with http")
	}

	newSpec := adsdomain.Ads{
		ID:        uuid.NewString(),
		ImageUrl:  spec.Image,
		Url:       spec.URL,
		StartDate: spec.StartDate,
		EndDate:   spec.EndDate,
	}

	return i.adsRepo.Create(newSpec)
}
