package shared

import "github.com/shopspring/decimal"

// GasTopUpRule defines buffer, minimum, rounding, and cap behavior for native gas top-ups.
type GasTopUpRule struct {
	BufferPercent    decimal.Decimal
	MinNativeBalance decimal.Decimal
	RoundingUnit     decimal.Decimal
	MaxTopUp         decimal.Decimal
}

// GasTopUpPolicy captures default and optional overrides for native vs contract transfers.
type GasTopUpPolicy struct {
	Default  GasTopUpRule
	Native   *GasTopUpRule
	Contract *GasTopUpRule
}

// Rule selects the policy rule for the transfer type.
func (p *GasTopUpPolicy) Rule(contractTransfer bool) (GasTopUpRule, bool) {
	if p == nil {
		return GasTopUpRule{}, false
	}
	if contractTransfer && p.Contract != nil {
		return *p.Contract, true
	}
	if !contractTransfer && p.Native != nil {
		return *p.Native, true
	}
	return p.Default, true
}
