// 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 (
	taskAiModelartsFieldNames          = builder.RawFieldNames(&TaskAiModelarts{})
	taskAiModelartsRows                = strings.Join(taskAiModelartsFieldNames, ",")
	taskAiModelartsRowsExpectAutoSet   = strings.Join(stringx.Remove(taskAiModelartsFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
	taskAiModelartsRowsWithPlaceHolder = strings.Join(stringx.Remove(taskAiModelartsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)

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

	defaultTaskAiModelartsModel struct {
		conn  sqlx.SqlConn
		table string
	}

	TaskAiModelarts struct {
		Id          int64  `db:"id"`           // 训练作业资源规格id
		TaskId      int64  `db:"task_id"`      // 任务id
		AdapterId   int64  `db:"adapter_id"`   // 执行任务的适配器id
		AdapterName string `db:"adapter_name"` // 适配器名称
		ClusterId   int64  `db:"cluster_id"`   // 集群id
		ClusterName string `db:"cluster_name"` // 集群名称
		Name        string `db:"name"`         // 任务名
		Replica     int64  `db:"replica"`      // 执行数
		JobId       string `db:"job_id"`       // 集群返回任务id
		StartTime   string `db:"start_time"`   // 开始时间
		RunningTime string `db:"running_time"` // 运行时间
		Result      string `db:"result"`       // 运行结果
		DeletedAt   string `db:"deleted_at"`   // 删除时间
		ImageId     string `db:"image_id"`     // 镜像id
		Cmd         string `db:"cmd"`          // 命令行
		FlavorId    string `db:"flavor_id"`    // 训练作业资源规格id
		Status      string `db:"status"`       // 任务状态
	}
)

func newTaskAiModelartsModel(conn sqlx.SqlConn) *defaultTaskAiModelartsModel {
	return &defaultTaskAiModelartsModel{
		conn:  conn,
		table: "`task_ai_modelarts`",
	}
}

func (m *defaultTaskAiModelartsModel) 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 *defaultTaskAiModelartsModel) FindOne(ctx context.Context, id int64) (*TaskAiModelarts, error) {
	query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", taskAiModelartsRows, m.table)
	var resp TaskAiModelarts
	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 *defaultTaskAiModelartsModel) Insert(ctx context.Context, data *TaskAiModelarts) (sql.Result, error) {
	query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, taskAiModelartsRowsExpectAutoSet)
	ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.TaskId, data.AdapterId, data.AdapterName, data.ClusterId, data.ClusterName, data.Name, data.Replica, data.JobId, data.StartTime, data.RunningTime, data.Result, data.DeletedAt, data.ImageId, data.Cmd, data.FlavorId, data.Status)
	return ret, err
}

func (m *defaultTaskAiModelartsModel) Update(ctx context.Context, data *TaskAiModelarts) error {
	query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, taskAiModelartsRowsWithPlaceHolder)
	_, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.AdapterId, data.AdapterName, data.ClusterId, data.ClusterName, data.Name, data.Replica, data.JobId, data.StartTime, data.RunningTime, data.Result, data.DeletedAt, data.ImageId, data.Cmd, data.FlavorId, data.Status, data.Id)
	return err
}

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