// Code generated by gen-table. DO NOT EDIT.
// Code generated by gen-table. DO NOT EDIT.
// Code generated by gen-table. DO NOT EDIT.

package repository

import (
	"time"

	"github.com/ch3nnn/webstack-go/internal/dal/model"
	"github.com/ch3nnn/webstack-go/internal/dal/query"

	"gorm.io/gen"
	"gorm.io/gen/field"
)

var _ iSysUserMenuDao = (*sysUserMenuDao)(nil)

// ------------------------------------
// SysUserMenu  ColumnName
// ------------------------------------
type iWhereSysUserMenuFunc interface {
	WhereByID(id int) func(dao gen.Dao) gen.Dao
	WhereByUserID(userId int) func(dao gen.Dao) gen.Dao
	WhereByMenuID(menuId int) func(dao gen.Dao) gen.Dao
	WhereByCreatedAt(createdAt time.Time) func(dao gen.Dao) gen.Dao
	WhereByUpdatedAt(updatedAt time.Time) func(dao gen.Dao) gen.Dao
	WhereByDeletedAt(deletedAt time.Time) func(dao gen.Dao) gen.Dao
}

// ------------------------------------
// SysUserMenu  Generate Function
// ------------------------------------
type iGenSysUserMenuFunc interface {
	Create(m *model.SysUserMenu) (*model.SysUserMenu, error)
	Delete(whereFunc ...func(dao gen.Dao) gen.Dao) error
	DeletePhysical(whereFunc ...func(dao gen.Dao) gen.Dao) error
	Update(v interface{}, whereFunc ...func(dao gen.Dao) gen.Dao) (rowsAffected int64, err error)
	FindCount(whereFunc ...func(dao gen.Dao) gen.Dao) (int64, error)
	FindOne(whereFunc ...func(dao gen.Dao) gen.Dao) (*model.SysUserMenu, error)
	FindAll(whereFunc ...func(dao gen.Dao) gen.Dao) ([]*model.SysUserMenu, error)
	FindPage(page int, pageSize int, orderColumns []field.Expr, whereFunc ...func(dao gen.Dao) gen.Dao) ([]*model.SysUserMenu, int64, error)
	Scan(result interface{}, whereFunc ...func(dao gen.Dao) gen.Dao) (err error)
	ScanPage(page int, pageSize int, orderColumns []field.Expr, result interface{}, whereFunc ...func(dao gen.Dao) gen.Dao) (count int64, err error)
}

type iSysUserMenuDao interface {
	iWhereSysUserMenuFunc
	iGenSysUserMenuFunc
}

type sysUserMenuDao struct {
	sysUserMenuDo query.ISysUserMenuDo
}

func (s *sysUserMenuDao) WhereByID(id int) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysUserMenu.ID.Eq(id))
	}
}

func (s *sysUserMenuDao) WhereByUserID(userId int) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysUserMenu.UserID.Eq(userId))
	}
}

func (s *sysUserMenuDao) WhereByMenuID(menuId int) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysUserMenu.MenuID.Eq(menuId))
	}
}

func (s *sysUserMenuDao) WhereByCreatedAt(createdAt time.Time) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysUserMenu.CreatedAt.Eq(createdAt))
	}
}

func (s *sysUserMenuDao) WhereByUpdatedAt(updatedAt time.Time) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysUserMenu.UpdatedAt.Eq(updatedAt))
	}
}

func (s *sysUserMenuDao) WhereByDeletedAt(deletedAt time.Time) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysUserMenu.DeletedAt.Eq(deletedAt))
	}
}

func (s *sysUserMenuDao) Create(m *model.SysUserMenu) (*model.SysUserMenu, error) {
	if err := s.sysUserMenuDo.Create(m); err != nil {
		return nil, err
	}
	return s.FindOne(s.WhereByID(m.ID))
}

func (s *sysUserMenuDao) FindCount(whereFunc ...func(dao gen.Dao) gen.Dao) (int64, error) {
	return s.sysUserMenuDo.Scopes(whereFunc...).Count()
}

func (s *sysUserMenuDao) FindOne(whereFunc ...func(dao gen.Dao) gen.Dao) (*model.SysUserMenu, error) {
	return s.sysUserMenuDo.Scopes(whereFunc...).First()
}

func (s *sysUserMenuDao) FindAll(whereFunc ...func(dao gen.Dao) gen.Dao) ([]*model.SysUserMenu, error) {
	return s.sysUserMenuDo.Scopes(whereFunc...).Find()
}

func (s *sysUserMenuDao) FindPage(page int, pageSize int, orderColumns []field.Expr, whereFunc ...func(dao gen.Dao) gen.Dao) ([]*model.SysUserMenu, int64, error) {
	return s.sysUserMenuDo.Scopes(whereFunc...).Order(orderColumns...).FindByPage((page-1)*pageSize, pageSize)
}

// 注意 当通过 struct 更新时，GORM 只会更新非零字段
// 如果想确保指定字段被更新，使用 map 来完成更新操作
func (s *sysUserMenuDao) Update(v interface{}, whereFunc ...func(dao gen.Dao) gen.Dao) (rowsAffected int64, err error) {
	info, err := s.sysUserMenuDo.Scopes(whereFunc...).Updates(v)
	if err != nil {
		return rowsAffected, err
	}

	return info.RowsAffected, nil
}

func (s *sysUserMenuDao) Delete(whereFunc ...func(dao gen.Dao) gen.Dao) error {
	if _, err := s.sysUserMenuDo.Scopes(whereFunc...).Delete(); err != nil {
		return err
	}
	return nil
}

func (s *sysUserMenuDao) DeletePhysical(whereFunc ...func(dao gen.Dao) gen.Dao) error {
	if _, err := s.sysUserMenuDo.Unscoped().Scopes(whereFunc...).Delete(); err != nil {
		return err
	}
	return nil
}

func (s *sysUserMenuDao) Scan(result interface{}, whereFunc ...func(dao gen.Dao) gen.Dao) (err error) {
	return s.sysUserMenuDo.Scopes(whereFunc...).Scan(result)
}

func (s *sysUserMenuDao) ScanPage(page int, pageSize int, orderColumns []field.Expr, result interface{}, whereFunc ...func(dao gen.Dao) gen.Dao) (count int64, err error) {
	return s.sysUserMenuDo.Scopes(whereFunc...).Order(orderColumns...).ScanByPage(result, (page-1)*pageSize, pageSize)
}
