package api

import (
	"net/http"

	v1 "github.com/AlchemyTelcoSolutions/callisto-so-bff/api/v1"
	"github.com/AlchemyTelcoSolutions/callisto-so-bff/cmd/app/config"
	"github.com/AlchemyTelcoSolutions/callisto-so-bff/internal/auth"
	"github.com/AlchemyTelcoSolutions/callisto-so-bff/internal/domain/model"
	"github.com/AlchemyTelcoSolutions/callisto-so-bff/internal/proxy"
	"github.com/AlchemyTelcoSolutions/callisto-so-bff/pkg/logger"
	"github.com/AlchemyTelcoSolutions/xutils-go/xlogger"
)

// SaleOrderService is the interface for dale Order Service
type SaleOrderService interface {
	CreateOrder(*http.Request) *model.SaleOrderResponse
	CreateOrderFromAuction(*http.Request, string) *model.SaleOrderResponse
	GetSOSummary(req *http.Request) *model.Response[model.SaleOrderSummaryResponse]
	UpdateSaleOrder(*http.Request, *v1.UpdateSaleOrderMultipartBody, string) *model.SaleOrderResponse
	ExportASNToFile(*http.Request, string, string) *model.SaleOrderExportASNResponse
}
type Server struct {
	logger       xlogger.Logger
	cfg          *config.Config
	saleOrderSvc SaleOrderService
	authSvc      auth.AuthService
	proxyService proxy.ProxyService
}

type ServerOptions struct {
	Logger       xlogger.Logger
	SaleOrderSvc SaleOrderService
	ProxySvc     proxy.ProxyService
	AuthSvc      auth.AuthService
	Config       *config.Config
}

func NewServer(opts ServerOptions) *Server {
	l := logger.New(opts.Logger)
	l.AddContextTag("domain", "api")
	return &Server{
		logger:       l,
		saleOrderSvc: opts.SaleOrderSvc,
		proxyService: opts.ProxySvc,
		authSvc:      opts.AuthSvc,
		cfg:          opts.Config,
	}
}
