package entity

import (
	"context"
	"gorm.io/gorm"
	"yx-dataset-server/app/schema"
)

// GetRobotDatasetDB 获取RobotDataset存储
func GetRobotDatasetDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
	return getDBWithModel(ctx, defDB, RobotDataset{})
}

// SchemaRobotDataset RobotDataset对象
type SchemaRobotDataset schema.RobotDataset

// ToRobotDataset 转换为RobotDataset实体
func (a SchemaRobotDataset) ToRobotDataset() *RobotDataset {
	item := &RobotDataset{
		RecordID:  a.RecordID,
		RobotId:   a.RobotId,
		DatasetId: a.DatasetId,
	}
	return item
}

// ToSchemaRobotDataset 转换为RobotDataset对象
func (a RobotDataset) ToSchemaRobotDataset() *schema.RobotDataset {
	item := &schema.RobotDataset{
		RecordID:  a.RecordID,
		RobotId:   a.RobotId,
		DatasetId: a.DatasetId,
	}
	return item
}

// RobotDataset RobotDataset实体
type RobotDataset struct {
	gorm.Model
	RecordID  string `gorm:"column:record_id;size:32;index;"`
	RobotId   string `gorm:"column:robot_id;size:32;index;"`
	DatasetId string `gorm:"column:dataset_id;size:32;index;"`
}

// RobotDatasets RobotDataset列表
type RobotDatasets []*RobotDataset

// ToSchemaRobotDatasets 转换为RobotDataset对象列表
func (a RobotDatasets) ToSchemaRobotDatasets() []*schema.RobotDataset {
	list := make([]*schema.RobotDataset, len(a))
	for i, item := range a {
		list[i] = item.ToSchemaRobotDataset()
	}
	return list
}
