package siteimp

import (
	"context"

	api "github.com/tech/sendico/pkg/api/http"
	"github.com/tech/sendico/pkg/messaging"
	"github.com/tech/sendico/pkg/mlogger"
	"github.com/tech/sendico/pkg/mservice"
	eapi "github.com/tech/sendico/server/interface/api"
)

type SiteAPI struct {
	logger   mlogger.Logger
	producer messaging.Producer
}

func (a *SiteAPI) Name() mservice.Type {
	return mservice.Site
}

func (a *SiteAPI) Finish(_ context.Context) error {
	return nil
}

func CreateAPI(a eapi.API) (*SiteAPI, error) {
	p := &SiteAPI{
		logger:   a.Logger().Named(mservice.Site),
		producer: a.Register().Messaging().Producer(),
	}

	a.Register().Handler(mservice.Site, "/request/demo", api.Post, p.demoRequest)
	a.Register().Handler(mservice.Site, "/request/contact", api.Post, p.contactRequest)
	a.Register().Handler(mservice.Site, "/request/call", api.Post, p.callRequest)
	return p, nil
}
