package chainassetsdb

import (
	"context"

	"github.com/tech/sendico/pkg/db/repository"
	"github.com/tech/sendico/pkg/model"
)

func (db *ChainAssetsDB) Resolve(ctx context.Context, chainAsset model.ChainAssetKey) (*model.ChainAssetDescription, error) {
	var assetDescription model.ChainAssetDescription
	assetField := repository.Field("asset")
	q := repository.Query().And(
		repository.Query().Filter(assetField.Dot("chain"), chainAsset.Chain),
		repository.Query().Filter(assetField.Dot("tokenSymbol"), chainAsset.TokenSymbol),
	)
	return &assetDescription, db.FindOne(ctx, q, &assetDescription)
}
