package dto

import (
	"github.com/tidbcloud/account/central/utils"
	"github.com/tidbcloud/account/idl/pbgen/proto/account"
	"github.com/tidbcloud/account/internel/dao/entity"
)

func ConvertAccountTrial(trial *entity.Trial) *account.Trial {
	return &account.Trial{
		Id:               trial.ID.Uint64(),
		CreatedAt:        utils.ToTimestamp(trial.CreatedAt),
		CreatedById:      trial.CreatedByID.Uint64(),
		OrgId:            trial.TenantID.Uint64(),
		StartedAt:        utils.ToTimestamp(trial.StartedAt),
		EstimatedEndedAt: utils.ToTimestamp(trial.EstimatedEndedAt),
		EndedAt:          utils.ToTimestamp(trial.EndedAt),
		TrialType:        string(trial.TrialType),
	}
}

func ConvertAccountTrials(trials []entity.Trial) []*account.Trial {
	result := make([]*account.Trial, len(trials))

	for i, trial := range trials {
		result[i] = ConvertAccountTrial(&trial)
	}

	return result
}
