// 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 _ iSysMenuDao = (*sysMenuDao)(nil)

// ------------------------------------
// SysMenu  ColumnName
// ------------------------------------
type iWhereSysMenuFunc interface {
	WhereByID(id int) func(dao gen.Dao) gen.Dao
	WhereByPid(pid int) func(dao gen.Dao) gen.Dao
	WhereByName(name string) func(dao gen.Dao) gen.Dao
	WhereByLink(link string) func(dao gen.Dao) gen.Dao
	WhereByIcon(icon string) func(dao gen.Dao) gen.Dao
	WhereByLevel(level int) func(dao gen.Dao) gen.Dao
	WhereBySort(sort int) func(dao gen.Dao) gen.Dao
	WhereByIsUsed(isUsed bool) 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
}

// ------------------------------------
// SysMenu  Generate Function
// ------------------------------------
type iGenSysMenuFunc interface {
	Create(m *model.SysMenu) (*model.SysMenu, 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.SysMenu, error)
	FindAll(whereFunc ...func(dao gen.Dao) gen.Dao) ([]*model.SysMenu, error)
	FindPage(page int, pageSize int, orderColumns []field.Expr, whereFunc ...func(dao gen.Dao) gen.Dao) ([]*model.SysMenu, 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 iSysMenuDao interface {
	iWhereSysMenuFunc
	iGenSysMenuFunc
}

type sysMenuDao struct {
	sysMenuDo query.ISysMenuDo
}

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

func (s *sysMenuDao) WhereByPid(pid int) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysMenu.Pid.Eq(pid))
	}
}

func (s *sysMenuDao) WhereByName(name string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysMenu.Name.Eq(name))
	}
}

func (s *sysMenuDao) WhereByLink(link string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysMenu.Link.Eq(link))
	}
}

func (s *sysMenuDao) WhereByIcon(icon string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysMenu.Icon.Eq(icon))
	}
}

func (s *sysMenuDao) WhereByLevel(level int) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysMenu.Level.Eq(level))
	}
}

func (s *sysMenuDao) WhereBySort(sort int) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysMenu.Sort.Eq(sort))
	}
}

func (s *sysMenuDao) WhereByIsUsed(isUsed bool) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysMenu.IsUsed.Is(isUsed))
	}
}

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

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

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

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

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

func (s *sysMenuDao) FindOne(whereFunc ...func(dao gen.Dao) gen.Dao) (*model.SysMenu, error) {
	return s.sysMenuDo.Scopes(whereFunc...).First()
}

func (s *sysMenuDao) FindAll(whereFunc ...func(dao gen.Dao) gen.Dao) ([]*model.SysMenu, error) {
	return s.sysMenuDo.Scopes(whereFunc...).Find()
}

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

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

	return info.RowsAffected, nil
}

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

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

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

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