package walletapi

import (
	walletv1 "hyapp.local/api/proto/wallet/v1"
	"hyapp/services/gateway-service/internal/transport/http/resourceview"
)

type overviewVIPData struct {
	Level         int32  `json:"level"`
	Name          string `json:"name"`
	Active        bool   `json:"active"`
	StartedAtMS   int64  `json:"started_at_ms"`
	ExpiresAtMS   int64  `json:"expires_at_ms"`
	ProgramType   string `json:"program_type,omitempty"`
	ConfigVersion int64  `json:"config_version,omitempty"`
	Unavailable   bool   `json:"unavailable,omitempty"`
}

type resourceData struct {
	ResourceID        int64    `json:"resource_id"`
	ResourceCode      string   `json:"resource_code"`
	ResourceType      string   `json:"resource_type"`
	Name              string   `json:"name"`
	Status            string   `json:"status"`
	Grantable         bool     `json:"grantable"`
	GrantStrategy     string   `json:"grant_strategy"`
	WalletAssetType   string   `json:"wallet_asset_type,omitempty"`
	WalletAssetAmount int64    `json:"wallet_asset_amount,omitempty"`
	PriceType         string   `json:"price_type,omitempty"`
	CoinPrice         int64    `json:"coin_price,omitempty"`
	GiftPointAmount   int64    `json:"gift_point_amount,omitempty"`
	UsageScopes       []string `json:"usage_scopes"`
	AssetURL          string   `json:"asset_url"`
	PreviewURL        string   `json:"preview_url"`
	AnimationURL      string   `json:"animation_url"`
	Format            string   `json:"format,omitempty"`
	MetadataJSON      string   `json:"metadata_json"`
	SortOrder         int32    `json:"sort_order"`
	CreatedAtMS       int64    `json:"created_at_ms"`
	UpdatedAtMS       int64    `json:"updated_at_ms"`
}

func resourcePointerFromProto(item *walletv1.Resource) *resourceData {
	if item == nil {
		return nil
	}
	data := resourceFromProto(item)
	return &data
}

func resourceFromProto(item *walletv1.Resource) resourceData {
	if item == nil {
		return resourceData{}
	}
	return resourceData{
		ResourceID:        item.GetResourceId(),
		ResourceCode:      item.GetResourceCode(),
		ResourceType:      item.GetResourceType(),
		Name:              item.GetName(),
		Status:            item.GetStatus(),
		Grantable:         item.GetGrantable(),
		GrantStrategy:     item.GetGrantStrategy(),
		WalletAssetType:   item.GetWalletAssetType(),
		WalletAssetAmount: item.GetWalletAssetAmount(),
		PriceType:         item.GetPriceType(),
		CoinPrice:         item.GetCoinPrice(),
		GiftPointAmount:   item.GetGiftPointAmount(),
		UsageScopes:       item.GetUsageScopes(),
		AssetURL:          item.GetAssetUrl(),
		PreviewURL:        item.GetPreviewUrl(),
		AnimationURL:      item.GetAnimationUrl(),
		Format:            resourceview.FormatFromMetadata(item.GetMetadataJson()),
		MetadataJSON:      item.GetMetadataJson(),
		SortOrder:         item.GetSortOrder(),
		CreatedAtMS:       item.GetCreatedAtMs(),
		UpdatedAtMS:       item.GetUpdatedAtMs(),
	}
}
