package gateway_funding_profile

import (
	"context"

	"github.com/tech/sendico/payments/storage/model"
	"github.com/tech/sendico/pkg/model/account_role"
	moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
)

// ReservePolicy defines where funds are blocked/released for pre-funding.
type ReservePolicy struct {
	DebitAccountRef string
	BlockAccountRef string
	FromRole        *account_role.AccountRole
	ToRole          *account_role.AccountRole
	ReleaseOnFail   bool
	ReleaseOnCancel bool
}

// GatewayFundingProfile is the single source for funding/block resolution.
type GatewayFundingProfile struct {
	GatewayID  string
	InstanceID string
	Rail       model.Rail
	Network    string
	Currency   string
	Mode       model.FundingMode

	FundingDestination *model.PaymentEndpoint
	FeeDestination     *model.PaymentEndpoint
	Reserve            *ReservePolicy
	DepositCheck       *model.DepositCheckPolicy

	Defaults map[string]string
}

// QuoteFundingGate describes pre-funding requirements before payout execution.
type QuoteFundingGate struct {
	Mode           model.FundingMode
	RequiredAmount *moneyv1.Money
	Funding        *model.PaymentEndpoint
	Fee            *model.PaymentEndpoint
	Reserve        *ReservePolicy
	DepositCheck   *model.DepositCheckPolicy
}

type FundingProfileRequest struct {
	OrganizationRef string
	GatewayID       string
	InstanceID      string
	Rail            model.Rail
	Network         string
	Currency        string
	Amount          *moneyv1.Money
	Source          *model.PaymentEndpoint
	Destination     *model.PaymentEndpoint
	Attributes      map[string]string
}

type FundingProfileResolver interface {
	ResolveGatewayFundingProfile(ctx context.Context, req FundingProfileRequest) (*GatewayFundingProfile, error)
}
