package factory

import (
	"github.com/linmadan/egglib-go/core/application"
	pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
)

func FastError(err error) error {
	return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}

func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) {
	var err error
	// 待优化分批下载,压缩
	var dataTable *domain.DataTable
	dataTable, err = starrocks.Query(options, starrocks.WrapQueryFuncWithDB(starrocks.DB))
	if err != nil {
		return nil, err
	}

	dataTable.Total, err = starrocks.WrapQueryCountWithDB(options, starrocks.DB)()
	if err != nil {
		return nil, err
	}
	return dataTable, nil
}

func FastQuerySetServices(transactionContext application.TransactionContext) (*domainService.QuerySetService, error) {
	return domainService.NewQuerySetService(transactionContext.(*pgTransaction.TransactionContext))
}