package gmodel

import "context"

// TODO: 使用model的属性做你想做的
func (u *LdapUserModel) Create(ctx context.Context, data *LdapUser) error {
	return u.db.WithContext(ctx).Model(&LdapUser{}).Create(&data).Error
}
func (u *LdapUserModel) Update(ctx context.Context, userDN string, data *LdapUser) error {
	return u.db.WithContext(ctx).Model(&LdapUser{}).Where("user_dn = ?", userDN).Updates(&data).Error
}

func (u *LdapUserModel) UpdateById(ctx context.Context, id int64, data *LdapUser) error {
	return u.db.WithContext(ctx).Model(&LdapUser{}).Where("id = ?", id).Updates(&data).Error
}

func (u *LdapUserModel) Delete(ctx context.Context, id int64) error {
	return u.db.WithContext(ctx).Model(&LdapUser{}).Where("id = ?", id).Delete(&LdapUser{}).Error
}

func (u *LdapUserModel) GetAllByIds(ctx context.Context, ids []int64) (resp []LdapUser, err error) {
	if len(ids) == 0 {
		return
	}
	err = u.db.WithContext(ctx).Model(&LdapUser{}).Where("id in (?)", ids).Find(&resp).Error
	return resp, err
}