// Code generated by godddx, DO AVOID EDIT.
package uniqueiddb

import (
	"context"

	"easyaudioencode/domain/uniqueid"

	"git.lnton.com/lnton/pkg/orm"
	"gorm.io/gorm"
)

var _ uniqueid.UniqueIDStorer = UniqueID{}

// UniqueID Related business namespaces
type UniqueID DB

// NewUniqueID instance object
func NewUniqueID(db *gorm.DB) UniqueID {
	return UniqueID{db: db}
}

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

// Get implements uniqueid.UniqueIDStorer.
func (d UniqueID) Get(ctx context.Context, model *uniqueid.UniqueID, opts ...orm.QueryOption) error {
	return orm.FirstWithContext(ctx, d.db, model, opts...)
}

// Add implements uniqueid.UniqueIDStorer.
func (d UniqueID) Add(ctx context.Context, model *uniqueid.UniqueID) error {
	return d.db.WithContext(ctx).Create(model).Error
}

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

// Del implements uniqueid.UniqueIDStorer.
func (d UniqueID) Del(ctx context.Context, model *uniqueid.UniqueID, opts ...orm.QueryOption) error {
	return orm.DeleteWithContext(ctx, d.db, model, opts...)
}

func (d UniqueID) Session(ctx context.Context, changeFns ...func(*gorm.DB) error) error {
	return d.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
		for _, fn := range changeFns {
			if err := fn(tx); err != nil {
				return err
			}
		}
		return nil
	})
}

func (d UniqueID) EditWithSession(tx *gorm.DB, model *uniqueid.UniqueID, changeFn func(b *uniqueid.UniqueID) error, opts ...orm.QueryOption) error {
	return orm.UpdateWithSession(tx, model, changeFn, opts...)
}
