// Package http add by blacknc <blacknc@163.com> at 2023/04/03 15:46:39
package http

import (
	"context"
)

func CreateOpLog(ctx context.Context, req *CreateOpLogReq) error {
	url := "/inner/sqleditor/oplog"
	resp := &CreateOpLogResp{}
	return postToSqleditor(ctx, url, req, resp)
}

func postToSqleditor(ctx context.Context, url string, req interface{}, resp interface{}) (err error) {
	defer func() {
		recordHttpCounterMetric("sqleditor", err)
	}()
	return postRequestToGlobal(ctx, "sqleditor", url, req, resp)
}

type CreateOpLogReq struct {
	OrgId           uint64 `json:"org_id,omitempty"`
	ProjectId       uint64 `json:"project_id,omitempty"`
	ClusterId       uint64 `json:"cluster_id,omitempty"`
	Chat2QuerySid   string `json:"chat2query_sid,omitempty"`
	EventType       string `json:"event_type,omitempty"`
	UserQuestion    string `json:"user_question,omitempty"`
	SqlContent      string `json:"sql_content,omitempty"`
	IsAccept        bool   `json:"is_accept"`
	StartTime       string `json:"start_time,omitempty"`
	EndTime         string `json:"end_time,omitempty"`
	Duration        int64  `json:"duration,omitempty"`
	AffectedRows    int64  `json:"affected_rows,omitempty"`
	AffectedColumns int64  `json:"affected_columns,omitempty"`
	Status          int32  `json:"status,omitempty"`
	ErrorMessage    string `json:"error_message,omitempty"`
	CreatedBy       string `json:"created_by,omitempty"`
	CreatedAt       int64  `json:"created_at,omitempty"`
	PromptVersion   string `json:"prompt_version,omitempty"`
	Databases       string `json:"databases,omitempty"`
	Channel         string `json:"channel,omitempty"`
}

type CreateOpLogResp struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (r *CreateOpLogResp) GetErrCode() int {
	return r.Code
}

func (r *CreateOpLogResp) GetErrMsg() string {
	return r.Message
}
