// Code generated by gowebx, DO AVOID EDIT.
package audioencodedb

import (
	"context"
	"easyaudioencode/internal/core/audioencode"
	"git.lnton.com/lnton/pkg/orm"
)

var _ audioencode.AudioEncodeStorer = AudioEncode{}

// AudioEncode Related business namespaces
type AudioEncode DB

// FindAll implements audioencode.AudioEncodeStorer.
func (d AudioEncode) FindAll(bs *[]*audioencode.AudioEncode) (int64, error) {
	db := d.db.Model(&audioencode.AudioEncode{})
	var total int64
	if err := db.Count(&total).Error; err != nil || total <= 0 {
		// 如果统计失败或者数量为0，则返回错误
		return 0, err
	}
	return total, db.Find(bs).Error
}

// Find implements audioencode.AudioEncodeStorer.
func (d AudioEncode) Find(ctx context.Context, bs *[]*audioencode.AudioEncode, page orm.Pager, opts ...orm.QueryOption) (int64, error) {
	return orm.FindWithContext(ctx, d.db, bs, page, opts...)
}

// Get implements audioencode.AudioEncodeStorer.
func (d AudioEncode) Get(ctx context.Context, model *audioencode.AudioEncode, opts ...orm.QueryOption) error {
	return orm.FirstWithContext(ctx, d.db, model, opts...)
}

// Add implements audioencode.AudioEncodeStorer.
func (d AudioEncode) Add(ctx context.Context, model *audioencode.AudioEncode) error {
	return d.db.WithContext(ctx).Create(model).Error
}

// Edit implements audioencode.AudioEncodeStorer.
func (d AudioEncode) Edit(ctx context.Context, model *audioencode.AudioEncode, changeFn func(*audioencode.AudioEncode), opts ...orm.QueryOption) error {
	return orm.UpdateWithContext(ctx, d.db, model, changeFn, opts...)
}

// Del implements audioencode.AudioEncodeStorer.
func (d AudioEncode) Del(ctx context.Context, model *audioencode.AudioEncode, opts ...orm.QueryOption) error {
	return orm.DeleteWithContext(ctx, d.db, model, opts...)
}

// EditStatus implements audioencode.AudioEncodeStorer.
func (d AudioEncode) EditStatus(status audioencode.EncodeStatus, id int) error {
	if err := d.db.Model(&audioencode.AudioEncode{}).Where(`id = ?`, id).Update("encode_status", status).Error; err != nil {
		return err
	}
	return nil
}
