package entity

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

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

// SchemaChatDataset ChatDataset对象
type SchemaChatDataset schema.ChatDataset

// ToChatDataset 转换为ChatDataset实体
func (a SchemaChatDataset) ToChatDataset() *ChatDataset {
	item := &ChatDataset{
		RecordID:        a.RecordID,
		ChatAssistantId: a.ChatAssistantId,
		DatasetId:       a.DatasetId,
		RagDataId:       a.RagDataId,
	}
	return item
}

// ToSchemaChatDataset 转换为ChatDataset对象
func (a ChatDataset) ToSchemaChatDataset() *schema.ChatDataset {
	item := &schema.ChatDataset{
		RecordID:        a.RecordID,
		ChatAssistantId: a.ChatAssistantId,
		DatasetId:       a.DatasetId,
		RagDataId:       a.RagDataId,
	}
	return item
}

// ChatDataset ChatDataset实体
type ChatDataset struct {
	gorm.Model
	RecordID        string `gorm:"column:record_id;size:32;index;"`
	ChatAssistantId string `gorm:"column:chat_assistant_id;size:32;index;"`
	DatasetId       string `gorm:"column:dataset_id;size:32;index;"`
	RagDataId       string `gorm:"column:rag_data_id;size:32;"`
}

// ChatDatasets ChatDataset列表
type ChatDatasets []*ChatDataset

// ToSchemaChatDatasets 转换为ChatDataset对象列表
func (a ChatDatasets) ToSchemaChatDatasets() []*schema.ChatDataset {
	list := make([]*schema.ChatDataset, len(a))
	for i, item := range a {
		list[i] = item.ToSchemaChatDataset()
	}
	return list
}
