export const BROKER_DETECTION_SETTINGS_KEY = 'BROKER_DETECTION_SETTINGS';

export type ListingFrequencyWindow = 'HOUR' | 'DAY' | 'MONTH' | 'LIFETIME';

export type ListingFrequencyRule = {
  window: ListingFrequencyWindow;
  maxCount: number;
  riskLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
  scoreImpact: number;
  enforced?: boolean;
};

export type BrokerDetectionSettings = {
  listingFrequencyRules: ListingFrequencyRule[];
  activityLogAllowlist: string[];
  activityLogRetentionDays?: number;
  jobFrequencyHours?: number;

  enableDeviceHeuristics?: boolean;
  deviceLinkedAccountWarnThreshold?: number;
  deviceLinkedAccountHighRiskThreshold?: number;
  deviceHeuristicCooldownDays?: number;
  deviceMaxNetworkScore?: number;
};

export const DEFAULT_BROKER_DETECTION_SETTINGS: BrokerDetectionSettings = {
  listingFrequencyRules: [
    { window: 'HOUR', maxCount: 1, riskLevel: 'MEDIUM', scoreImpact: 20, enforced: false },
    { window: 'DAY', maxCount: 2, riskLevel: 'HIGH', scoreImpact: 45, enforced: false },
    { window: 'MONTH', maxCount: 8, riskLevel: 'HIGH', scoreImpact: 60, enforced: false },
    { window: 'LIFETIME', maxCount: 25, riskLevel: 'CRITICAL', scoreImpact: 80, enforced: false },
  ],
  enableDeviceHeuristics: true,
  deviceLinkedAccountWarnThreshold: 1,
  deviceLinkedAccountHighRiskThreshold: 4,
  deviceHeuristicCooldownDays: 30,
  deviceMaxNetworkScore: 80,
  activityLogAllowlist: [
    'ACCOUNT_CREATED',
    'LOGIN',
    'LISTING_CREATED',
    'LISTING_STATUS_CHANGED',
    'LISTING_AUTO_ARCHIVED',
    'MESSAGE_SENT',
  ],
  activityLogRetentionDays: 180,
  jobFrequencyHours: 6,
};
