package resource

import (
	"strings"
)

type ResourceGroupItem struct {
	GroupItemID       int64
	GroupID           int64
	ItemType          string
	ResourceID        int64
	Resource          Resource
	WalletAssetType   string
	WalletAssetAmount int64
	Quantity          int64
	DurationMS        int64
	SortOrder         int32
	CreatedAtMS       int64
	UpdatedAtMS       int64
}

type ResourceGroup struct {
	AppCode         string
	GroupID         int64
	GroupCode       string
	Name            string
	Status          string
	Description     string
	SortOrder       int32
	Items           []ResourceGroupItem
	CreatedByUserID int64
	UpdatedByUserID int64
	CreatedAtMS     int64
	UpdatedAtMS     int64
}

type ResourceGroupItemInput struct {
	ItemType          string
	ResourceID        int64
	WalletAssetType   string
	WalletAssetAmount int64
	Quantity          int64
	DurationMS        int64
	SortOrder         int32
}

type ListResourceGroupsQuery struct {
	AppCode    string
	Status     string
	Keyword    string
	Page       int32
	PageSize   int32
	ActiveOnly bool
}

type ResourceGroupCommand struct {
	AppCode        string
	GroupID        int64
	GroupCode      string
	Name           string
	Status         string
	Description    string
	SortOrder      int32
	Items          []ResourceGroupItemInput
	OperatorUserID int64
}

func ValidGrantStrategy(value string) bool {
	switch strings.ToLower(strings.TrimSpace(value)) {
	case GrantStrategyWalletCredit, GrantStrategyNewEntitlement, GrantStrategyExtendExpiry, GrantStrategyIncreaseQuantity, GrantStrategySetActiveFlag:
		return true
	default:
		return false
	}
}

func NormalizeGroupItemType(value string) string {
	value = strings.ToLower(strings.TrimSpace(value))
	if value == "" {
		return GroupItemTypeResource
	}
	return value
}

func ValidGroupItemType(value string) bool {
	switch NormalizeGroupItemType(value) {
	case GroupItemTypeResource, GroupItemTypeWalletAsset:
		return true
	default:
		return false
	}
}
