package pquery

import (
	"context"
	"time"

	"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/agg"
	"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/prepo"
	"github.com/tech/sendico/pkg/mlogger"
	"go.mongodb.org/mongo-driver/v2/bson"
)

// Service provides read models for orchestration-v2 payments.
type Service interface {
	GetPayment(ctx context.Context, in GetPaymentInput) (*agg.Payment, error)
	ListPayments(ctx context.Context, in ListPaymentsInput) (*ListPaymentsOutput, error)
}

// GetPaymentInput scopes one payment lookup.
type GetPaymentInput struct {
	OrganizationRef bson.ObjectID
	PaymentRef      string
}

// ListPaymentsInput scopes cursor-based listing.
type ListPaymentsInput struct {
	OrganizationRef bson.ObjectID
	States          []agg.State
	QuotationRef    string
	CreatedFrom     *time.Time
	CreatedTo       *time.Time
	Cursor          *prepo.ListCursor
	Limit           int32
}

// ListPaymentsOutput is one list page.
type ListPaymentsOutput struct {
	Items      []*agg.Payment
	NextCursor *prepo.ListCursor
}

// Dependencies defines query service dependencies.
type Dependencies struct {
	Repository prepo.Repository
	Logger     mlogger.Logger
}

func New(deps Dependencies) (Service, error) {
	return newService(deps)
}
