package booking

import (
	"github.com/rjNemo/rentease/internal/config"
)

func (bs Service) ParseFromApi(rawContent string) (*Booking, error) {
	b, err := bs.parser.Parse(rawContent)
	if err != nil {
		return nil, err
	}

	itm := b.Items[0]
	b = bs.Create(b.From, b.To, b.Name, b.PhoneNumber, b.Email, b.Platform, b.CustomerNumber, b.PlatformFees, b.ExternalId)

	if item, ok := config.NewHost().Items[itm.Item]; ok {
		bs.CreateItem(b.Id, item, itm.Quantity, itm.Price, itm.PaymentMethod, b.CustomerNumber, b.Platform)
	}

	return b, nil
}
