You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: login_policy.go
    path of file: ./repos/next-terminal/server/repository
    
    the code of the file until where you have to start completion: package repository

import (
	"context"

	"next-terminal/server/model"
)

var LoginPolicyRepository = new(loginPolicyRepository)

type loginPolicyRepository struct {
	baseRepository
}

func (r loginPolicyRepository) Find(c context.Context, pageIndex, pageSize int, name, userId, order, field string) (o []model.LoginPolicy, total int64, err error) {
	m := model.LoginPolicy{}
	db := r.GetDB(c).Table(m.TableName()).Joins("left join login_policies_ref as ref on login_policies.id = ref.login_policy_id").Group("login_policies.id")
	dbCounter := r.GetDB(c).Table(m.TableName()).Joins("left join login_policies_ref as ref on login_policies.id = ref.login_policy_id").Group("login_policies.id")

	if len(name) > 0 {
		db = db.Where("login_policies.name like ?", "%"+name+"%")
		dbCounter = dbCou
    
func (r loginPolicyRepository) Find(c context.Context, pageIndex, pageSize int, name, userId, order, field string) (o []model.LoginPolicy, total int64, err error) {
	m := model.LoginPolicy{}
	db := r.GetDB(c).Table(m.TableName()).Joins("left join login_policies_ref as ref on login_policies.id = ref.login_policy_id").Group("login_policies.id")
	dbCounter := r.GetDB(c).Table(m.TableName()).Joins("left join login_policies_ref as ref on login_policies.id = ref.login_policy_id").Group("login_policies.id")

	if len(name) > 0 {
		db = db.Where("login_policies.name like ?", "%"+name+"%")
		dbCounter = dbCounter.Where("login_policies.name like ?", "%"+name+"%")
	}

	if len(userId) > 0 {
		db = db.Where("ref.user_id = ?", userId)
		dbCounter = dbCounter.Where("ref.user_id = ?", userId)
	}

	err = dbCounter.Count(&total).Error
	if err != nil {
		return nil, 0, err
	}

	if order == "" {
		order = "asc"
	} else if order == "ascend" {
		order = "asc"
	} else {
		order = "desc"
	}

	if field == "name" {
		field = "login_policies.name"
	} else {
		field = "login_policies.priority"
	}

	err = db.Order(field + " " + order).Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Error
	if o == nil {
		o = make([]model.LoginPolicy, 0)
	}
	return
}