#!/usr/bin/env python3
"""
GPS Pricing Calculator
Arizona Computer Guru - MSP Pricing Tool
"""

# Pricing Constants
GPS_TIERS = {
    'basic': {
        'name': 'GPS-BASIC: Essential Protection',
        'price_per_endpoint': 19,
        'features': [
            '24/7 System Monitoring & Alerting',
            'Automated Patch Management',
            'Remote Management & Support',
            'Endpoint Security (Antivirus)',
            'Monthly Health Reports'
        ]
    },
    'pro': {
        'name': 'GPS-PRO: Business Protection (MOST POPULAR)',
        'price_per_endpoint': 26,
        'features': [
            'All GPS-Basic features',
            'Advanced EDR',
            'Email Security',
            'Dark Web Monitoring',
            'Security Training',
            'Cloud Monitoring (M365/Google)'
        ]
    },
    'advanced': {
        'name': 'GPS-ADVANCED: Maximum Protection',
        'price_per_endpoint': 39,
        'features': [
            'All GPS-Pro features',
            'Advanced Threat Intelligence',
            'Ransomware Rollback',
            'Compliance Tools (HIPAA, PCI-DSS, SOC 2)',
            'Priority Response',
            'Enhanced SaaS Backup'
        ]
    }
}

EQUIPMENT_PACK = {
    'base_price': 25,  # Up to 10 devices
    'base_devices': 10,
    'additional_device_price': 3
}

SUPPORT_PLANS = {
    'essential': {
        'name': 'Essential Support',
        'price': 200,
        'hours_included': 2,
        'effective_rate': 100,
        'response_time': 'Next business day',
        'coverage': 'Business hours'
    },
    'standard': {
        'name': 'Standard Support (MOST POPULAR)',
        'price': 380,
        'hours_included': 4,
        'effective_rate': 95,
        'response_time': '8-hour guarantee',
        'coverage': 'Business hours'
    },
    'premium': {
        'name': 'Premium Support',
        'price': 540,
        'hours_included': 6,
        'effective_rate': 90,
        'response_time': '4-hour guarantee',
        'coverage': 'After-hours emergency'
    },
    'priority': {
        'name': 'Priority Support',
        'price': 850,
        'hours_included': 10,
        'effective_rate': 85,
        'response_time': '2-hour guarantee',
        'coverage': '24/7 emergency'
    }
}

BLOCK_TIME = {
    '10hr': {'hours': 10, 'price': 1500, 'rate': 150},
    '20hr': {'hours': 20, 'price': 2600, 'rate': 130},
    '30hr': {'hours': 30, 'price': 3000, 'rate': 100}
}

OVERAGE_RATE = 175


def calculate_equipment_pack(num_devices):
    """Calculate equipment pack pricing"""
    if num_devices == 0:
        return 0
    if num_devices <= EQUIPMENT_PACK['base_devices']:
        return EQUIPMENT_PACK['base_price']
    else:
        additional = num_devices - EQUIPMENT_PACK['base_devices']
        return EQUIPMENT_PACK['base_price'] + (additional * EQUIPMENT_PACK['additional_device_price'])


def calculate_gps_quote(endpoints, tier='pro', equipment_devices=0, support_plan=None, block_time=None):
    """
    Calculate a complete GPS quote

    Args:
        endpoints: Number of endpoints
        tier: GPS tier (basic, pro, advanced)
        equipment_devices: Number of equipment devices
        support_plan: Support plan key (essential, standard, premium, priority)
        block_time: Block time key (10hr, 20hr, 30hr)

    Returns:
        dict with pricing breakdown
    """
    # GPS Monitoring
    gps_tier_data = GPS_TIERS.get(tier, GPS_TIERS['pro'])
    gps_cost = endpoints * gps_tier_data['price_per_endpoint']

    # Equipment Pack
    equipment_cost = calculate_equipment_pack(equipment_devices)

    # Support Plan
    support_cost = 0
    support_hours = 0
    support_data = None
    if support_plan:
        support_data = SUPPORT_PLANS.get(support_plan)
        if support_data:
            support_cost = support_data['price']
            support_hours = support_data['hours_included']

    # Block Time (one-time or as needed)
    block_cost = 0
    block_hours = 0
    if block_time:
        block_data = BLOCK_TIME.get(block_time)
        if block_data:
            block_cost = block_data['price']
            block_hours = block_data['hours']

    # Calculate totals
    monthly_total = gps_cost + equipment_cost + support_cost
    annual_total = monthly_total * 12

    # Per endpoint cost
    total_endpoints = endpoints + equipment_devices
    per_endpoint_cost = monthly_total / total_endpoints if total_endpoints > 0 else 0

    return {
        'gps': {
            'tier': gps_tier_data['name'],
            'endpoints': endpoints,
            'price_per_endpoint': gps_tier_data['price_per_endpoint'],
            'monthly_cost': gps_cost
        },
        'equipment': {
            'devices': equipment_devices,
            'monthly_cost': equipment_cost
        },
        'support': {
            'plan': support_data['name'] if support_data else 'None',
            'monthly_cost': support_cost,
            'hours_included': support_hours,
            'effective_rate': support_data['effective_rate'] if support_data else 0
        },
        'block_time': {
            'hours': block_hours,
            'cost': block_cost
        },
        'totals': {
            'monthly': monthly_total,
            'annual': annual_total,
            'per_endpoint': round(per_endpoint_cost, 2)
        }
    }


def print_quote(quote):
    """Print formatted quote"""
    print("\n" + "="*60)
    print("GPS PRICING QUOTE")
    print("="*60)

    print(f"\nGPS Monitoring: {quote['gps']['tier']}")
    print(f"  {quote['gps']['endpoints']} endpoints × ${quote['gps']['price_per_endpoint']}/month = ${quote['gps']['monthly_cost']}")

    if quote['equipment']['devices'] > 0:
        print(f"\nEquipment Pack:")
        print(f"  {quote['equipment']['devices']} devices = ${quote['equipment']['monthly_cost']}/month")

    if quote['support']['monthly_cost'] > 0:
        print(f"\nSupport Plan: {quote['support']['plan']}")
        print(f"  ${quote['support']['monthly_cost']}/month ({quote['support']['hours_included']} hours included)")
        print(f"  Effective rate: ${quote['support']['effective_rate']}/hour")

    if quote['block_time']['hours'] > 0:
        print(f"\nPrepaid Block Time:")
        print(f"  {quote['block_time']['hours']} hours = ${quote['block_time']['cost']} (never expires)")

    print("\n" + "-"*60)
    print(f"MONTHLY TOTAL: ${quote['totals']['monthly']}")
    print(f"ANNUAL TOTAL: ${quote['totals']['annual']}")
    print(f"Per Endpoint/Device Cost: ${quote['totals']['per_endpoint']}/month")
    print("="*60 + "\n")


# Example usage
if __name__ == "__main__":
    print("GPS PRICING CALCULATOR - Arizona Computer Guru")
    print("="*60)

    # Example 1: Small Office
    print("\nExample 1: Small Office (10 endpoints + 4 devices)")
    quote1 = calculate_gps_quote(
        endpoints=10,
        tier='pro',
        equipment_devices=4,
        support_plan='standard'
    )
    print_quote(quote1)

    # Example 2: Growing Business
    print("\nExample 2: Growing Business (22 endpoints)")
    quote2 = calculate_gps_quote(
        endpoints=22,
        tier='pro',
        support_plan='premium'
    )
    print_quote(quote2)

    # Example 3: Established Company
    print("\nExample 3: Established Company (42 endpoints)")
    quote3 = calculate_gps_quote(
        endpoints=42,
        tier='pro',
        support_plan='priority'
    )
    print_quote(quote3)
