// Code generated by goctl. DO NOT EDIT.

package models

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

	"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 (
	hpcInstanceCenterFieldNames          = builder.RawFieldNames(&HpcInstanceCenter{})
	hpcInstanceCenterRows                = strings.Join(hpcInstanceCenterFieldNames, ",")
	hpcInstanceCenterRowsExpectAutoSet   = strings.Join(stringx.Remove(hpcInstanceCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
	hpcInstanceCenterRowsWithPlaceHolder = strings.Join(stringx.Remove(hpcInstanceCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)

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

	defaultHpcInstanceCenterModel struct {
		conn  sqlx.SqlConn
		table string
	}

	HpcInstanceCenter struct {
		Id                   int64     `db:"id" json:"id"`                                       // 平台唯一id
		App                  string    `db:"app" json:"app"`                                     // 应用名称
		LogoPath             string    `db:"logo_path" json:"logoPath"`                          // logo图像的位置
		InstanceName         string    `db:"instance_name" json:"instanceName"`                  // 实例名称
		InstanceType         int64     `db:"instance_type" json:"instanceType"`                  // 实例类型（1是应用实例，2是模型实例）
		InstanceClass        string    `db:"instance_class" json:"instanceClass"`                // 实例类别
		InstanceClassChinese string    `db:"instance_class_chinese" json:"instanceClassChinese"` // 实例类别中文描述
		Description          string    `db:"description" json:"description"`                     // 描述
		Status               int64     `db:"status" json:"status"`                               // 状态状态 0-不可用，1-可用
		Version              string    `db:"version" json:"version"`                             // 版本
		CreatedAt            time.Time `db:"created_at" json:"createdAt"`                        // 创建时间
		UpdatedAt            time.Time `db:"updated_at" json:"updatedAt"`                        // 更新时间
	}
)

func newHpcInstanceCenterModel(conn sqlx.SqlConn) *defaultHpcInstanceCenterModel {
	return &defaultHpcInstanceCenterModel{
		conn:  conn,
		table: "`hpc_instance_center`",
	}
}

func (m *defaultHpcInstanceCenterModel) 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 *defaultHpcInstanceCenterModel) FindOne(ctx context.Context, id int64) (*HpcInstanceCenter, error) {
	query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", hpcInstanceCenterRows, m.table)
	var resp HpcInstanceCenter
	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 *defaultHpcInstanceCenterModel) Insert(ctx context.Context, data *HpcInstanceCenter) (sql.Result, error) {
	query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, hpcInstanceCenterRowsExpectAutoSet)
	ret, err := m.conn.ExecCtx(ctx, query, data.LogoPath, data.InstanceName, data.InstanceType, data.InstanceClass, data.InstanceClassChinese, data.Description, data.Version)
	return ret, err
}

func (m *defaultHpcInstanceCenterModel) Update(ctx context.Context, data *HpcInstanceCenter) error {
	query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, hpcInstanceCenterRowsWithPlaceHolder)
	_, 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 *defaultHpcInstanceCenterModel) tableName() string {
	return m.table
}
