// 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 (
	"github.com/ch3nnn/webstack-go/internal/dal/model"
	"github.com/ch3nnn/webstack-go/internal/dal/query"

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

var _ iSysConfigDao = (*sysConfigDao)(nil)

// ------------------------------------
// SysConfig  ColumnName
// ------------------------------------
type iWhereSysConfigFunc interface {
	WhereByID(id int) func(dao gen.Dao) gen.Dao
	WhereByAboutSite(aboutSite string) func(dao gen.Dao) gen.Dao
	WhereByAboutAuthor(aboutAuthor string) func(dao gen.Dao) gen.Dao
	WhereByIsAbout(isAbout bool) func(dao gen.Dao) gen.Dao
	WhereBySiteTitle(siteTitle string) func(dao gen.Dao) gen.Dao
	WhereBySiteKeyword(siteKeyword string) func(dao gen.Dao) gen.Dao
	WhereBySiteDesc(siteDesc string) func(dao gen.Dao) gen.Dao
	WhereBySiteRecord(siteRecord string) func(dao gen.Dao) gen.Dao
	WhereBySiteLogo(siteLogo string) func(dao gen.Dao) gen.Dao
	WhereBySiteFavicon(siteFavicon string) func(dao gen.Dao) gen.Dao
	WhereBySiteURL(siteUrl string) func(dao gen.Dao) gen.Dao
}

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

type sysConfigDao struct {
	sysConfigDo query.ISysConfigDo
}

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

func (s *sysConfigDao) WhereByAboutSite(aboutSite string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysConfig.AboutSite.Eq(aboutSite))
	}
}

func (s *sysConfigDao) WhereByAboutAuthor(aboutAuthor string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysConfig.AboutAuthor.Eq(aboutAuthor))
	}
}

func (s *sysConfigDao) WhereByIsAbout(isAbout bool) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysConfig.IsAbout.Is(isAbout))
	}
}

func (s *sysConfigDao) WhereBySiteTitle(siteTitle string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysConfig.SiteTitle.Eq(siteTitle))
	}
}

func (s *sysConfigDao) WhereBySiteKeyword(siteKeyword string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysConfig.SiteKeyword.Eq(siteKeyword))
	}
}

func (s *sysConfigDao) WhereBySiteDesc(siteDesc string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysConfig.SiteDesc.Eq(siteDesc))
	}
}

func (s *sysConfigDao) WhereBySiteRecord(siteRecord string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysConfig.SiteRecord.Eq(siteRecord))
	}
}

func (s *sysConfigDao) WhereBySiteLogo(siteLogo string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysConfig.SiteLogo.Eq(siteLogo))
	}
}

func (s *sysConfigDao) WhereBySiteFavicon(siteFavicon string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysConfig.SiteFavicon.Eq(siteFavicon))
	}
}

func (s *sysConfigDao) WhereBySiteURL(siteUrl string) func(dao gen.Dao) gen.Dao {
	return func(dao gen.Dao) gen.Dao {
		return dao.Where(query.SysConfig.SiteURL.Eq(siteUrl))
	}
}

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

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

func (s *sysConfigDao) FindOne(whereFunc ...func(dao gen.Dao) gen.Dao) (*model.SysConfig, error) {
	return s.sysConfigDo.Scopes(whereFunc...).First()
}

func (s *sysConfigDao) FindAll(whereFunc ...func(dao gen.Dao) gen.Dao) ([]*model.SysConfig, error) {
	return s.sysConfigDo.Scopes(whereFunc...).Find()
}

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

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

	return info.RowsAffected, nil
}

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

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

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

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