// Code generated by goctl. DO NOT EDIT.

package models

import (
	"context"
	"database/sql"
	"fmt"
	"strings"

	"github.com/zeromicro/go-zero/core/stores/builder"
	"github.com/zeromicro/go-zero/core/stores/sqlc"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"github.com/zeromicro/go-zero/core/stringx"
)

var (
	aiInferDeployInstanceFieldNames          = builder.RawFieldNames(&AiInferDeployInstance{})
	aiInferDeployInstanceRows                = strings.Join(aiInferDeployInstanceFieldNames, ",")
	aiInferDeployInstanceRowsExpectAutoSet   = strings.Join(stringx.Remove(aiInferDeployInstanceFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
	aiInferDeployInstanceRowsWithPlaceHolder = strings.Join(stringx.Remove(aiInferDeployInstanceFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)

type (
	aiInferDeployInstanceModel interface {
		Insert(ctx context.Context, data *AiInferDeployInstance) (sql.Result, error)
		FindOne(ctx context.Context, id int64) (*AiInferDeployInstance, error)
		Update(ctx context.Context, data *AiInferDeployInstance) error
		Delete(ctx context.Context, id int64) error
	}

	defaultAiInferDeployInstanceModel struct {
		conn  sqlx.SqlConn
		table string
	}

	AiInferDeployInstance struct {
		Id                   int64  `db:"id" json:"id,string"`
		DeployInstanceTaskId int64  `db:"deploy_instance_task_id" json:"deployTaskId,string"`
		InstanceId           string `db:"instance_id" json:"instanceId"`
		InstanceName         string `db:"instance_name" json:"instanceName"`
		AdapterId            int64  `db:"adapter_id" json:"adapterId,string"`
		AdapterName          string `db:"adapter_name" json:"adapterName"	`
		ClusterId            int64  `db:"cluster_id" json:"clusterId,string"`
		ClusterName          string `db:"cluster_name" json:"clusterName"`
		ModelName            string `db:"model_name" json:"modelName"`
		ModelType            string `db:"model_type" json:"modelType"`
		InferCard            string `db:"infer_card" json:"inferCard"`
		Status               string `db:"status" json:"status"`
		CreateTime           string `db:"create_time" json:"createTime"`
		UpdateTime           string `db:"update_time" json:"updateTime"`
		ClusterType          string `db:"cluster_type" json:"clusterType"`
	}
)

func newAiInferDeployInstanceModel(conn sqlx.SqlConn) *defaultAiInferDeployInstanceModel {
	return &defaultAiInferDeployInstanceModel{
		conn:  conn,
		table: "`ai_infer_deploy_instance`",
	}
}

func (m *defaultAiInferDeployInstanceModel) withSession(session sqlx.Session) *defaultAiInferDeployInstanceModel {
	return &defaultAiInferDeployInstanceModel{
		conn:  sqlx.NewSqlConnFromSession(session),
		table: "`ai_infer_deploy_instance`",
	}
}

func (m *defaultAiInferDeployInstanceModel) Delete(ctx context.Context, id int64) error {
	query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
	_, err := m.conn.ExecCtx(ctx, query, id)
	return err
}

func (m *defaultAiInferDeployInstanceModel) FindOne(ctx context.Context, id int64) (*AiInferDeployInstance, error) {
	query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", aiInferDeployInstanceRows, m.table)
	var resp AiInferDeployInstance
	err := m.conn.QueryRowCtx(ctx, &resp, query, id)
	switch err {
	case nil:
		return &resp, nil
	case sqlc.ErrNotFound:
		return nil, ErrNotFound
	default:
		return nil, err
	}
}

func (m *defaultAiInferDeployInstanceModel) Insert(ctx context.Context, data *AiInferDeployInstance) (sql.Result, error) {
	query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, aiInferDeployInstanceRowsExpectAutoSet)
	ret, err := m.conn.ExecCtx(ctx, query, data.InstanceId, data.InstanceName, data.AdapterId, data.AdapterName, data.ClusterId, data.ClusterName, data.ModelName, data.ModelType, data.InferCard, data.Status)
	return ret, err
}

func (m *defaultAiInferDeployInstanceModel) Update(ctx context.Context, data *AiInferDeployInstance) error {
	query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, aiInferDeployInstanceRowsWithPlaceHolder)
	_, err := m.conn.ExecCtx(ctx, query, data.InstanceId, data.InstanceName, data.AdapterId, data.AdapterName, data.ClusterId, data.ClusterName, data.ModelName, data.ModelType, data.InferCard, data.Status, data.Id)
	return err
}

func (m *defaultAiInferDeployInstanceModel) tableName() string {
	return m.table
}
