# Corrected Business Logic - Ver2 Fixes

## ✅ **Fixed Issues**

### **1. Removed Non-Existent Fields**

- **Removed**: `featureList` and `featureSet` from field mapping
- **Impact**: Prevents Salesforce query errors for non-existent fields
- **Solution**: Use hardcoded tier features in `getTierTemplate()`

### **2. Clarified Addon Logic**

**Addons can be:**

- **Standalone**: Independent monthly/onetime addons
- **Bundled**: Monthly addon + Onetime installation paired via `bundledAddonId`

**Key Points:**

- Addons use `Item_Class__c = "Add-on"` (even for installations)
- Service installations use `Item_Class__c = "Installation"`
- Bundle relationship via `isBundledAddon` + `bundledAddonId` fields

### **3. Fixed Order Validation**

**Before (Incorrect):**

```typescript
// Too restrictive - only allowed exactly 1 service SKU
const mainServiceSkus = data.skus.filter(sku => !sku.includes("addon") && !sku.includes("fee"));
return mainServiceSkus.length === 1;
```

**After (Correct):**

```typescript
// Allows service + installations + addons
const mainServiceSkus = data.skus.filter(sku => {
  const upperSku = sku.toUpperCase();
  return (
    !upperSku.includes("INSTALL") &&
    !upperSku.includes("ADDON") &&
    !upperSku.includes("ACTIVATION") &&
    !upperSku.includes("FEE")
  );
});
return mainServiceSkus.length >= 1; // At least one service required
```

## 📋 **Product Classification Matrix**

| Product Type         | Item_Class\_\_c | SKU Pattern                    | Billing Cycle | Bundle Logic         |
| -------------------- | --------------- | ------------------------------ | ------------- | -------------------- |
| Internet Plan        | Service         | `INTERNET-SILVER-*`            | Monthly       | N/A                  |
| Service Installation | Installation    | `INTERNET-INSTALL-*`           | Onetime       | Standalone           |
| Monthly Addon        | Add-on          | `INTERNET-ADDON-DENWA`         | Monthly       | Can be bundled       |
| Addon Installation   | Add-on          | `INTERNET-ADDON-DENWA-INSTALL` | Onetime       | Bundled with monthly |
| SIM Plan             | Service         | `SIM-DATA-*`                   | Monthly       | N/A                  |
| SIM Activation       | Activation      | `SIM-ACTIVATION-FEE`           | Onetime       | Standalone           |

## 🔧 **Valid Order Examples**

### **Internet Order with Addons**

```json
{
  "orderType": "Internet",
  "skus": [
    "INTERNET-SILVER-HOME-1G", // Main service
    "INTERNET-INSTALL-SINGLE", // Service installation
    "INTERNET-ADDON-DENWA", // Monthly addon
    "INTERNET-ADDON-DENWA-INSTALL" // Addon installation (bundled)
  ]
}
```

### **SIM Order with Addons**

```json
{
  "orderType": "SIM",
  "skus": [
    "SIM-DATA-VOICE-50GB", // Main service
    "SIM-ACTIVATION-FEE", // Required activation
    "SIM-ADDON-VOICE-MAIL" // Standalone addon
  ],
  "configurations": {
    "simType": "eSIM",
    "eid": "89049032000000000000000000000001"
  }
}
```

## 🛡️ **Business Rules**

### **Internet Orders**

- ✅ Must have at least 1 main service SKU
- ✅ Can have multiple installations, addons, fees
- ✅ Bundled addons (monthly + installation) allowed

### **SIM Orders**

- ✅ Must specify `simType` in configurations
- ✅ eSIM orders must provide `eid`
- ✅ Can include activation fees and addons

### **Addon Bundling**

- ✅ Monthly addon + Onetime installation = Bundle
- ✅ Both use `Item_Class__c = "Add-on"`
- ✅ Linked via `bundledAddonId` field
- ✅ Frontend displays as single bundle item

## 🎯 **Key Differences from Main Branch**

| Aspect           | Main Branch                  | Ver2 (Corrected)             |
| ---------------- | ---------------------------- | ---------------------------- |
| Field Mapping    | Includes non-existent fields | Only existing SF fields      |
| Order Validation | Simple, permissive           | Structured with clear rules  |
| Addon Logic      | Basic bundling               | Comprehensive bundle support |
| Business Rules   | Hardcoded in services        | Zod schemas with validation  |
| Error Handling   | Basic try/catch              | Structured error responses   |

This ensures ver2 works correctly with your Salesforce setup while maintaining the flexible addon/installation logic you need.
