import { UserPlan } from './types';

/**
 * Plan-based limits and configuration
 */
export const PLAN_LIMITS = {
    free: {
        retentionDays: 7,
        maxMonitors: 3,
        minFrequency: 60, // minutes
        features: ['email_alerts', 'basic_noise_filtering'],
    },
    pro: {
        retentionDays: 90,
        maxMonitors: 20,
        minFrequency: 5,
        features: ['email_alerts', 'slack_integration', 'webhook_integration', 'keyword_alerts', 'smart_noise_filtering', 'audit_export'],
    },
    business: {
        retentionDays: 365,
        maxMonitors: 100,
        minFrequency: 1,
        features: ['email_alerts', 'slack_integration', 'webhook_integration', 'keyword_alerts', 'smart_noise_filtering', 'audit_export', 'api_access', 'team_members'],
    },
    enterprise: {
        retentionDays: 730, // 2 years
        maxMonitors: Infinity,
        minFrequency: 1,
        features: ['email_alerts', 'slack_integration', 'webhook_integration', 'keyword_alerts', 'smart_noise_filtering', 'audit_export', 'api_access', 'team_members', 'custom_integrations', 'sla'],
    },
} as const;

/**
 * Get the retention period in days for a user plan
 */
export function getRetentionDays(plan: UserPlan): number {
    return PLAN_LIMITS[plan]?.retentionDays || PLAN_LIMITS.free.retentionDays;
}

/**
 * Get the maximum number of monitors for a user plan
 */
export function getMaxMonitors(plan: UserPlan): number {
    return PLAN_LIMITS[plan]?.maxMonitors || PLAN_LIMITS.free.maxMonitors;
}

/**
 * Check if a plan has a specific feature
 */
export function hasFeature(plan: UserPlan, feature: string): boolean {
    const planConfig = PLAN_LIMITS[plan] || PLAN_LIMITS.free;
    return planConfig.features.includes(feature as any);
}

/**
 * Webhook retry configuration
 */
export const WEBHOOK_CONFIG = {
    maxRetries: 3,
    retryDelayMs: 1000,
    timeoutMs: 10000,
};

/**
 * App configuration
 */
export const APP_CONFIG = {
    appUrl: process.env.APP_URL || 'http://localhost:3000',
    emailFrom: process.env.EMAIL_FROM || 'noreply@websitemonitor.com',
};
