package model

import (
	"strings"

	"github.com/tech/sendico/pkg/db/storable"
	"github.com/tech/sendico/pkg/mservice"
)

// PaymentRoute defines an allowed rail transition for orchestration.
type PaymentRoute struct {
	storable.Base `bson:",inline" json:",inline"`

	FromRail        Rail   `bson:"fromRail" json:"fromRail"`
	ToRail          Rail   `bson:"toRail" json:"toRail"`
	Network         string `bson:"network,omitempty" json:"network,omitempty"`
	RequiresObserve bool   `bson:"requiresObserve,omitempty" json:"requiresObserve,omitempty"`
	IsEnabled       bool   `bson:"isEnabled" json:"isEnabled"`
}

// Collection implements storable.Storable.
func (*PaymentRoute) Collection() string {
	return mservice.PaymentRoutes
}

// Normalize standardizes route fields for consistent indexing and matching.
func (r *PaymentRoute) Normalize() {
	if r == nil {
		return
	}
	r.FromRail = normalizeRail(r.FromRail)
	r.ToRail = normalizeRail(r.ToRail)
	r.Network = strings.ToUpper(strings.TrimSpace(r.Network))
}

// PaymentRouteFilter selects routes for lookup.
type PaymentRouteFilter struct {
	FromRail  Rail
	ToRail    Rail
	Network   string
	IsEnabled *bool
}

// PaymentRouteList holds route results.
type PaymentRouteList struct {
	Items []*PaymentRoute
}
