package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/dialect/entsql"
	"entgo.io/ent/schema"
	"entgo.io/ent/schema/field"
	"entgo.io/ent/schema/index"
	"github.com/suyuan32/simple-admin-common/orm/ent/mixins"
)

// CompapiJob holds the schema definition for the CompapiJob entity.
type CompapiAsynctask struct {
	ent.Schema
}

// Fields of the CompapiJob.
func (CompapiAsynctask) Fields() []ent.Field {

	return []ent.Field{
		field.String("auth_token").Annotations(entsql.WithComments(true)).Comment("发起请求者的授权token"),
		field.String("event_type").Default("fastgpt").Annotations(entsql.WithComments(true)).Comment("请求目标类型"),
		field.String("chat_id").Optional().Default("").Annotations(entsql.WithComments(true)).Comment("会话ID"),
		field.String("response_chat_item_id").Optional().Default(""),
		field.Uint64("organization_id").Positive().Comment("organization_id | 租户ID"),
		field.String("openai_base").Annotations(entsql.WithComments(true)).Comment("待请求的大模型服务地址"),
		field.String("openai_key").Annotations(entsql.WithComments(true)).Comment("待请求的大模型服务密钥授权token"),
		field.String("request_raw").Annotations(entsql.WithComments(true)).Comment("请求参数结构字符串"),
		field.String("response_raw").Optional().Default("").Annotations(entsql.WithComments(true)).Comment("请求响应结构字符串"),
		field.String("callback_url").MaxLen(255).Annotations(entsql.WithComments(true)).Comment("callback_url | 异步执行回调地址"),
		//field.Uint64("callback_response_code").Positive().Comment("callback返回状态码"),
		field.String("callback_response_raw").Optional().Default("").Annotations(entsql.WithComments(true)).Comment("callback返回结构字符串"),
		//field.Int8("dist_status").Optional().Default(0).Annotations(entsql.WithComments(true)).Comment("dist status | 分发状态 0 未 1 已"),
		//field.Time("dist_at").Optional().Annotations(entsql.WithComments(true)).Comment("Dist Time | 分发时间"),
		field.String("model").Optional().Default("").Annotations(entsql.WithComments(true)).Comment("所用大模型"),
		field.Int8("task_status").Optional().Default(10).Annotations(entsql.WithComments(true)).Comment("callback_status | 任务完成状态 10 任务就绪 20 请求API完成 30 请求回调完成 60 任务暂停 70 任务失败"),
		field.Int8("retry_count").Optional().Default(0).Annotations(entsql.WithComments(true)).Comment("retry count | 重试次数"),
		field.String("last_error").Optional().Default("").Annotations(entsql.WithComments(true)).Comment("最后一次出错信息"),
	}
}

func (CompapiAsynctask) Mixin() []ent.Mixin {
	return []ent.Mixin{
		mixins.IDMixin{},
	}
}

func (CompapiAsynctask) Indexes() []ent.Index {
	return []ent.Index{
		//index.Fields("dist_status"),
		index.Fields("task_status"),
	}
}

func (CompapiAsynctask) Edges() []ent.Edge { return []ent.Edge{} }

func (CompapiAsynctask) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.WithComments(true),
		entsql.Annotation{Table: "compapi_asynctask"},
	}
}
