// 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/sqlx"
	"github.com/zeromicro/go-zero/core/stringx"
)

var (
	aiInstanceCenterFieldNames          = builder.RawFieldNames(&AiInstanceCenter{})
	aiInstanceCenterRows                = strings.Join(aiInstanceCenterFieldNames, ",")
	aiInstanceCenterRowsExpectAutoSet   = strings.Join(stringx.Remove(aiInstanceCenterFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
	aiInstanceCenterRowsWithPlaceHolder = strings.Join(stringx.Remove(aiInstanceCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)

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

	defaultAiInstanceCenterModel struct {
		conn  sqlx.SqlConn
		table string
	}

	AiInstanceCenter struct {
		Id                   int64  `db:"id"`                     // 平台唯一id
		LogoPath             string `db:"logo_path"`              // logo图像的位置
		InstanceName         string `db:"instance_name"`          // 实例名称
		InstanceType         int32  `db:"instance_type"`          // 实例类型（1是应用实例，2是模型实例）
		InstanceClass        string `db:"instance_class"`         // 实例类别
		InstanceClassChinese string `db:"instance_class_chinese"` // 实例类别中文描述
		Description          string `db:"description"`            // 描述
		Version              string `db:"version"`                // 版本
		CreateTime           string `db:"create_time"`            // 创建时间
		UpdateTime           string `db:"update_time"`            // 更新时间
	}
)

func newAiInstanceCenterModel(conn sqlx.SqlConn) *defaultAiInstanceCenterModel {
	return &defaultAiInstanceCenterModel{
		conn:  conn,
		table: "`ai_instance_center`",
	}
}

func (m *defaultAiInstanceCenterModel) 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 *defaultAiInstanceCenterModel) FindOne(ctx context.Context, id int64) (*AiInstanceCenter, error) {
	query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", aiInstanceCenterRows, m.table)
	var resp AiInstanceCenter
	err := m.conn.QueryRowCtx(ctx, &resp, query, id)
	switch err {
	case nil:
		return &resp, nil
	case sqlx.ErrNotFound:
		return nil, ErrNotFound
	default:
		return nil, err
	}
}

func (m *defaultAiInstanceCenterModel) Insert(ctx context.Context, data *AiInstanceCenter) (sql.Result, error) {
	query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, aiInstanceCenterRowsExpectAutoSet)
	ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.LogoPath, data.InstanceName, data.InstanceType, data.InstanceClass, data.InstanceClassChinese, data.Description, data.Version)
	return ret, err
}

func (m *defaultAiInstanceCenterModel) Update(ctx context.Context, data *AiInstanceCenter) error {
	query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, aiInstanceCenterRowsWithPlaceHolder)
	_, err := m.conn.ExecCtx(ctx, query, data.LogoPath, data.InstanceName, data.InstanceType, data.InstanceClass, data.InstanceClassChinese, data.Description, data.Version, data.Id)
	return err
}

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