package entity

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

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

// SchemaChatAssistant ChatAssistant对象
type SchemaChatAssistant schema.ChatAssistant

// ToChatAssistant 转换为ChatAssistant实体
func (a SchemaChatAssistant) ToChatAssistant() *ChatAssistant {
	item := &ChatAssistant{
		RecordID:  a.RecordID,
		UserId:    a.UserId,
		OrgId:     a.OrgId,
		Name:      a.Name,
		Desc:      a.Desc,
		Source:    a.Source,
		RagChatId: a.RagChatId,
		CreatorId: a.CreatorId,
	}
	return item
}

// ToSchemaChatAssistant 转换为ChatAssistant对象
func (a ChatAssistant) ToSchemaChatAssistant() *schema.ChatAssistant {
	item := &schema.ChatAssistant{
		RecordID:  a.RecordID,
		UserId:    a.UserId,
		OrgId:     a.OrgId,
		Name:      a.Name,
		Desc:      a.Desc,
		Source:    a.Source,
		RagChatId: a.RagChatId,
		CreatorId: a.CreatorId,
		CreatedAt: a.CreatedAt,
	}
	return item
}

// ChatAssistant ChatAssistant实体
type ChatAssistant struct {
	gorm.Model
	RecordID  string `gorm:"column:record_id;size:32;index;"`  // 记录id
	UserId    string `gorm:"column:user_id;size:32;index;"`    // 所属用户id
	OrgId     string `gorm:"column:org_id;size:32;index;"`     // 所属组织id
	Name      string `gorm:"column:name;size:50;"`             // 助手名称
	Desc      string `gorm:"column:desc;size:30;"`             // 描述
	Source    int    `gorm:"column:source;"`                   // 来源 1h5 2 钉钉机器人
	RagChatId string `gorm:"column:rag_chat_id;size:32;"`      // rag_chat_id
	CreatorId string `gorm:"column:creator_id;size:32;index;"` // 创建人id
}

// ChatAssistants ChatAssistant列表
type ChatAssistants []*ChatAssistant

// ToSchemaChatAssistants 转换为ChatAssistant对象列表
func (a ChatAssistants) ToSchemaChatAssistants() []*schema.ChatAssistant {
	list := make([]*schema.ChatAssistant, len(a))
	for i, item := range a {
		list[i] = item.ToSchemaChatAssistant()
	}
	return list
}
