package transform

import (
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models"
	"strings"
)

func TransformToTableDomainModelFromPgModels(tableModel *models.Table) (*domain.Table, error) {
	for _, f := range tableModel.DataFields {
		f.SQLType = strings.ToUpper(f.SQLType)
	}
	return &domain.Table{
		TableId:        tableModel.TableId,
		TableType:      tableModel.TableType,
		Name:           tableModel.Name,
		SQLName:        tableModel.SQLName,
		ParentId:       tableModel.ParentId,
		DataFieldIndex: tableModel.DataFieldIndex,
		PK:             tableModel.PK,
		DataFields:     tableModel.DataFields,
		ManualFields:   tableModel.ManualFields,
		CreatedAt:      tableModel.CreatedAt,
		UpdatedAt:      tableModel.UpdatedAt,
		DeletedAt:      tableModel.DeletedAt,
		Version:        tableModel.Version,
		RowCount:       tableModel.RowCount,
		Context:        tableModel.Context,
		TableInfo:      tableModel.TableInfo,
		ApplyAt:        tableModel.ApplyAt,
	}, nil
}