package district

import (
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/district"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
)

func relationPredicates(province, city, area, street string, level uint32, lvOperator core.Operator) []predicate.District {
	var predicates []predicate.District
	if province != "" {
		predicates = append(predicates, district.ProvinceEQ(province))
	}
	if city != "" {
		predicates = append(predicates, district.Or(district.CityEQ(city), district.CityEQ("")))
	}
	if area != "" {
		predicates = append(predicates, district.Or(district.AreaEQ(area), district.AreaEQ("")))
	}
	if street != "" {
		predicates = append(predicates, district.Or(district.StreetEQ(street), district.StreetEQ("")))
	}
	if level != 0 {
		switch lvOperator {
		case core.Operator_EQ:
			predicates = append(predicates, district.LevelEQ(level))
		case core.Operator_GT:
			predicates = append(predicates, district.LevelGT(level))
		case core.Operator_LT:
			predicates = append(predicates, district.LevelLT(level))
		case core.Operator_GTE:
			predicates = append(predicates, district.LevelGTE(level))
		case core.Operator_LTE:
			predicates = append(predicates, district.LevelLTE(level))
		}
	}
	return predicates
}
