Files
doormile_backend/constants/delivery_category.go

77 lines
2.5 KiB
Go

package constants
import "strings"
// What a client delivers, and what that implies operationally.
//
// ─── One vocabulary, not two ───────────────────────────────────────────────
//
// Categories driven by pricing, onboarding, and logistics.
// Non-perishable goods like Steel, Clothing, Electronics, Automotive have return paths.
// Perishable goods like Food, Meat, and Fresh Produce have NO return option.
var DeliveryCategories = map[string]bool{
"General": true,
"Documents": true,
"Electronics": true,
"Clothing": true,
"Fragile": true,
"Medical": true,
"Automotive": true,
"Steel": true,
"Food": true,
"Meat": true,
"FreshProduce": true,
}
// DeliveryCategoryList is the same set, ordered, for anything that renders a choice.
var DeliveryCategoryList = []string{
"General", "Documents", "Electronics", "Clothing",
"Fragile", "Medical", "Automotive", "Steel", "Food", "Meat", "FreshProduce",
}
// CategoryDefault is what a client with no category recorded is treated as.
const CategoryDefault = "General"
// NonReturnableCategories defines categories of goods that cannot be returned
// (Food items, Meat items, Fresh produce/perishables). Returning them causes
// spoilage and health risks. Non-perishables like Steel, Clothing, Electronics, etc. can be returned.
var NonReturnableCategories = map[string]bool{
"food": true,
"meat": true,
"raw meat": true,
"fresh produce": true,
"freshproduce": true,
"fresh": true,
"perishable": true,
"fish": true,
"seafood": true,
"poultry": true,
"dairy": true,
"vegetables": true,
"fruits": true,
}
// IsPerishableCategory checks if a category or item description is perishable (food, meat, fresh produce).
func IsPerishableCategory(category string) bool {
cat := strings.ToLower(strings.TrimSpace(category))
if cat == "" {
return false
}
if NonReturnableCategories[cat] {
return true
}
if strings.Contains(cat, "food") || strings.Contains(cat, "meat") || strings.Contains(cat, "fresh") {
return true
}
return false
}
// ReverseLogisticsAllowed reports whether a return journey makes sense for
// what this client or parcel ships.
//
// Food items, Meat items, and Fresh produce CANNOT be returned.
// Products like Steel, Electronics, Clothing, and Automotive CAN be returned.
func ReverseLogisticsAllowed(category string) bool {
return !IsPerishableCategory(category)
}