# Dubai Market Specific Logic

## Property Types - Dubai Context

### Off-Plan vs Ready Properties

#### Off-Plan Properties
Properties under construction or in pre-launch phase.

**Database Fields:**
```sql
completion_status = 'off_plan'
completion_date = '2025-12-31'  -- Expected completion
handover_date = '2026-03-31'   -- When keys handed over
construction_progress = 45.00   -- Percentage complete
payment_plan_available = TRUE
```

**Key Characteristics:**
- **Oqood Registration**: Pre-registration system by DLD
- **Escrow Account**: Required for all off-plan sales
- **Payment Plans**: Flexible installment options
- **Post-Handover Payment**: Extended payment after delivery

**Payment Plan Structure:**
```typescript
interface PaymentPlan {
  downPaymentPercent: number;      // Typically 10-24%
  constructionPercent: number;     // During construction
  handoverPercent: number;         // On completion
  postHandoverPercent: number;     // After handover (optional)
  postHandoverMonths: number;      // Extended payment period
  milestonePayments: Milestone[];  // Construction-linked
}

interface Milestone {
  milestone: string;    // "Foundation", "20% Construction", etc.
  percent: number;
  dueDate?: Date;
}
```

**UI Indicators:**
```tsx
// Badge component
<OffPlanBadge 
  completionDate="2025-12"
  progress={45}
  paymentPlan={true}
/>

// Visual: Blue badge with construction icon
// Shows: "Handover Q4 2025 • 45% Complete • Payment Plan"
```

#### Ready Properties
Completed properties available for immediate possession.

**Database Fields:**
```sql
completion_status = 'ready'
completion_date = '2020-06-15'  -- Actual completion
handover_date = '2020-08-01'   -- When handed over
is_vacant = TRUE                -- Ready to move in
```

**Key Characteristics:**
- **Title Deed**: Immediate transfer possible
- **Ejari**: Tenant registration system
- **DEWA/FEWA**: Utility connections ready
- **Service Charges**: Ongoing maintenance fees

**UI Indicators:**
```tsx
<ReadyBadge />
// Visual: Green badge with checkmark
// Shows: "Ready to Move • Title Deed Available"
```

### Completion Status Pipeline

```
OFF_PLAN
    ↓ (Construction starts)
UNDER_CONSTRUCTION
    ├─ 0%: Foundation
    ├─ 25%: Structure rising
    ├─ 50%: Superstructure
    ├─ 75%: Finishing works
    ↓ 100%
READY
    ↓
HANDED_OVER (to owner)
```

## Currency & Pricing

### AED (UAE Dirham) Formatting

**Standard Format:**
```typescript
// Format utility
function formatAED(amount: number): string {
  return new Intl.NumberFormat('en-AE', {
    style: 'currency',
    currency: 'AED',
    minimumFractionDigits: 0,
    maximumFractionDigits: 0,
  }).format(amount);
}

// Examples:
formatAED(2500000);     // "AED 2,500,000"
formatAED(125000);      // "AED 125,000"
formatAED(7500);        // "AED 7,500"
formatAED(1200000.50);  // "AED 1,200,001"
```

**Display Variations:**
```tsx
// Compact (for cards)
<AED amount={2500000} compact />  // "AED 2.5M"

// Full (for detail page)
<AED amount={2500000} />           // "AED 2,500,000"

// With per sqft
<PricePerSqft price={2500000} area={1350} />  // "AED 1,852/sqft"
```

### Price Ranges by Area (Dubai Market)

```typescript
const dubaiPriceRanges = {
  // Luxury Areas
  'Palm Jumeirah': { min: 3000000, max: 50000000, avg: 15000000 },
  'Downtown Dubai': { min: 1500000, max: 25000000, avg: 5000000 },
  'Dubai Marina': { min: 1200000, max: 15000000, avg: 3500000 },
  'Jumeirah Beach Residence': { min: 1500000, max: 12000000, avg: 3000000 },
  
  // Mid-Market
  'Jumeirah Village Circle': { min: 600000, max: 3000000, avg: 1200000 },
  'Dubai Sports City': { min: 500000, max: 2500000, avg: 1000000 },
  'Dubai Silicon Oasis': { min: 450000, max: 2000000, avg: 850000 },
  
  // Affordable
  'International City': { min: 300000, max: 800000, avg: 500000 },
  'Discovery Gardens': { min: 400000, max: 1000000, avg: 650000 },
};
```

## RERA Compliance

### Registration Numbers

#### Agent - BRN (Broker Registration Number)
```typescript
interface AgentVerification {
  brn: string;                    // Format: BRN-XXXXX
  reraPermitNumber: string;         // Format: XXXXX
  reraVerifiedAt: Date;
  reraVerificationStatus: 'pending' | 'verified' | 'rejected';
}

// Validation
function validateBRN(brn: string): boolean {
  return /^BRN-\d{5,6}$/.test(brn);
}

function validateRERAPermit(permit: string): boolean {
  return /^\d{5,6}$/.test(permit);
}
```

#### Agency - ORN (Office Registration Number)
```typescript
interface AgencyVerification {
  orn: string;                     // Format: ORN-XXXXX
  tradeLicenseNumber: string;       // Dubai DED license
  companyRegistrationNumber: string;
  reraVerifiedAt: Date;
  reraVerificationStatus: 'pending' | 'verified' | 'rejected';
}

// Validation
function validateORN(orn: string): boolean {
  return /^ORN-\d{5,6}$/.test(orn);
}
```

### Display Requirements

**Property Listings:**
```tsx
// RERA permit must be visible on all listings
<PropertyRERABadge 
  permitNumber="12345"
  verified={true}
  agentName="Ahmed Hassan"
  agencyName="Dubai Prime Properties"
/>

// Footer on every listing page:
// "RERA Permit No. 12345 • Broker: Ahmed Hassan (BRN-67890) 
//  • Agency: Dubai Prime Properties (ORN-12345)"
```

## Key Dubai Locations

### Location Hierarchy
```
Dubai (Emirate)
├── Dubai Marina (Area)
│   ├── Dubai Marina Towers (Sub-community)
│   ├── Emaar 6 Towers (Sub-community)
│   └── Marina Promenade (Sub-community)
├── Downtown Dubai (Area)
│   ├── Burj Khalifa District
│   ├── Old Town
│   └── Dubai Opera District
├── Palm Jumeirah (Area)
│   ├── Fronds A-P (Sub-communities)
│   └── Golden Mile
├── Business Bay (Area)
├── Jumeirah Village Circle (Area)
└── ... (150+ areas)
```

### Popular Search Areas
```typescript
const popularDubaiAreas = [
  { id: 1, name: 'Downtown Dubai', searchVolume: 'Very High', avgPrice: 5000000 },
  { id: 2, name: 'Dubai Marina', searchVolume: 'Very High', avgPrice: 3500000 },
  { id: 3, name: 'Palm Jumeirah', searchVolume: 'High', avgPrice: 15000000 },
  { id: 4, name: 'Business Bay', searchVolume: 'High', avgPrice: 2000000 },
  { id: 5, name: 'Jumeirah Beach Residence', searchVolume: 'High', avgPrice: 3000000 },
  { id: 6, name: 'Jumeirah Village Circle', searchVolume: 'Medium', avgPrice: 1200000 },
  { id: 7, name: 'Dubai Hills Estate', searchVolume: 'Medium', avgPrice: 2800000 },
  { id: 8, name: 'Mohammed Bin Rashid City', searchVolume: 'Medium', avgPrice: 4500000 },
];
```

## Dubai-Specific Search Filters

### Completion Status Filter
```tsx
<CompletionFilter 
  options={[
    { value: 'ready', label: 'Ready to Move', count: 1250 },
    { value: 'off_plan', label: 'Off-Plan', count: 890 },
    { value: 'under_construction', label: 'Under Construction', count: 340 },
  ]}
/>
```

### Payment Plan Filter
```tsx
<PaymentPlanFilter 
  options={[
    { value: 'any', label: 'Any' },
    { value: 'available', label: 'Payment Plan Available' },
    { value: 'post_handover', label: 'Post-Handover Payment' },
    { value: 'no_plan', label: 'No Payment Plan' },
  ]}
/>
```

### Developer Filter
```tsx
<DeveloperFilter 
  developers={[
    { id: 1, name: 'Emaar Properties', logo: '...', projectCount: 45 },
    { id: 2, name: 'Nakheel', logo: '...', projectCount: 32 },
    { id: 3, name: 'DAMAC Properties', logo: '...', projectCount: 67 },
    { id: 4, name: 'Meraas', logo: '...', projectCount: 23 },
    { id: 5, name: 'Dubai Properties', logo: '...', projectCount: 28 },
  ]}
/>
```

### Handover Date Filter
```tsx
<HandoverDateFilter 
  options={[
    { value: '2024', label: '2024' },
    { value: '2025', label: '2025' },
    { value: '2026', label: '2026' },
    { value: '2027+', label: '2027 & Beyond' },
  ]}
/>
```

## Dubai Legal Framework

### Required Disclosures

**Off-Plan Property:**
```tsx
<OffPlanDisclosure 
  escrowAccount="1234567890"
  reraPermit="BV-2023-001"
  developer="Emaar Properties"
  completionDate="2025-12-31"
/>

// Shows:
// - Escrow account number (verified)
// - RERA project permit
// - Developer track record
// - Construction timeline
// - Payment schedule
```

**Ready Property:**
```tsx
<ReadyDisclosure 
  titleDeedReady={true}
  serviceCharges={25} // AED per sqft
  communityFees={15000} // Annual
/>
```

## Area-Specific Features

### Freehold vs Leasehold
```typescript
const ownershipTypeByArea: Record<string, 'freehold' | 'leasehold'> = {
  'Downtown Dubai': 'freehold',
  'Dubai Marina': 'freehold',
  'Palm Jumeirah': 'freehold',
  'Business Bay': 'freehold',
  'Jumeirah': 'leasehold',  // UAE nationals only
  'Umm Suqeim': 'leasehold',
};
```

### Service Charges
```typescript
const serviceChargesByArea: Record<string, number> = {
  'Palm Jumeirah': 35,      // AED per sqft annually
  'Downtown Dubai': 25,
  'Dubai Marina': 18,
  'Business Bay': 15,
  'Jumeirah Village Circle': 8,
};
```

## Dubai Market Insights

### Market Trends API
```http
GET /market/insights
Query:
  area_id              - Specific area
  property_type        - Filter by type
  time_period          - 1m | 3m | 6m | 1y | 2y

Response:
{
  "area": "Downtown Dubai",
  "property_type": "apartment",
  "period": "1y",
  "insights": {
    "avg_price_change": 5.2,        // Percentage change
    "avg_price_per_sqft": 1850,
    "transaction_volume": 1250,
    "inventory_count": 450,
    "days_on_market_avg": 45,
    "price_trend": [
      { "month": "2024-01", "avg_price": 2100000 },
      { "month": "2024-02", "avg_price": 2150000 },
      // ...
    ],
    "hot_properties": [...],
    "new_launches": [...]
  }
}
```

## API Constants

### Dubai-Specific Enums
```typescript
export enum CompletionStatus {
  OFF_PLAN = 'off_plan',
  UNDER_CONSTRUCTION = 'under_construction',
  READY = 'ready',
  HANDED_OVER = 'handed_over',
}

export enum ListingType {
  SALE = 'sale',
  RENT = 'rent',
}

export enum FurnishedType {
  UNFURNISHED = 'unfurnished',
  SEMI_FURNISHED = 'semi_furnished',
  FULLY_FURNISHED = 'fully_furnished',
}

export enum ViewType {
  SEA = 'sea',
  CITY = 'city',
  MARINA = 'marina',
  GARDEN = 'garden',
  POOL = 'pool',
  PARK = 'park',
  GOLF = 'golf',
  DESERT = 'desert',
}
```

## Validation Rules

### Dubai-Specific Validations
```typescript
const dubaiValidations = {
  // Phone numbers
  phone: {
    pattern: /^\+971[0-9]{9}$/,
    example: '+971501234567',
    message: 'Enter UAE phone with country code (+971)',
  },
  
  // Emirates ID
  emiratesId: {
    pattern: /^784-[0-9]{4}-[0-9]{7}-[0-9]{1}$/,
    example: '784-2001-1234567-1',
  },
  
  // RERA Permit
  reraPermit: {
    pattern: /^[0-9]{5,6}$/,
    example: '12345',
  },
  
  // BRN
  brn: {
    pattern: /^BRN-[0-9]{5,6}$/,
    example: 'BRN-12345',
  },
  
  // ORN
  orn: {
    pattern: /^ORN-[0-9]{5,6}$/,
    example: 'ORN-12345',
  },
  
  // Price (AED)
  price: {
    min: 50000,
    max: 500000000, // 500M AED
    message: 'Price must be between AED 50,000 and AED 500M',
  },
};
```

## Cultural Considerations

### RTL Support
```tsx
// Next.js i18n configuration
export const i18nConfig = {
  locales: ['en', 'ar'],
  defaultLocale: 'en',
  rtlLocales: ['ar'],
};

// Component usage
<html dir={isRTL ? 'rtl' : 'ltr'}>
  <body className={isRTL ? 'font-arabic' : 'font-sans'}>
    {/* Content */}
  </body>
</html>
```

### Working Hours
```typescript
const dubaiWorkingHours = {
  weekday: { open: '09:00', close: '18:00' },
  friday: { open: '14:00', close: '18:00' }, // Jumu'ah
  saturday: 'closed',
  timezone: 'Asia/Dubai',
};
```
