package models

import "WorldEpcho/src/datasource"

type InspirationUsageLog struct {
	ID                  int64  `xorm:"'id' pk" json:"id"`
	AuthId              string `xorm:"auth_id" json:"authId"`
	DpId                int64  `xorm:"dp_id"  json:"dpId"`
	DpName              string `xorm:"dp_name" json:"dpName"`
	WorldId             int64  `xorm:"world_id" json:"worldId"`
	WorldName           string `xorm:"world_name" json:"worldName"`
	ChatTime            int64  `xorm:"chat_time" json:"chatTime"`
	InspirationConsumed int64  `xorm:"inspiration_consumed" json:"InspirationConsumed"`
}

// 增加记录
func AddInspirationUsageLog(log *InspirationUsageLog) (int64, error) {
	affected, err := datasource.Engine.Insert(log)
	return affected, err
}

// 删除记录
func DeleteInspirationUsageLog(id int64) (int64, error) {
	log := InspirationUsageLog{ID: id}
	affected, err := datasource.Engine.Delete(&log)
	return affected, err
}

// 修改记录
func UpdateInspirationUsageLog(log *InspirationUsageLog) (int64, error) {
	affected, err := datasource.Engine.ID(log.ID).Update(log)
	return affected, err
}

// 查询单条记录
func GetInspirationUsageLog(id int64) (*InspirationUsageLog, error) {
	var log InspirationUsageLog
	_, err := datasource.Engine.ID(id).Get(&log)
	return &log, err
}

// 查询多条记录
// 此处仅作为示例，你可能需要根据实际情况调整参数
func FindInspirationUsageLogs(authId string) ([]InspirationUsageLog, error) {
	var logs []InspirationUsageLog
	err := datasource.Engine.Where("auth_id = ?", authId).Find(&logs)
	return logs, err
}
