"""Central plan limits for trial vs licensed PhotoPick.

Pricing / plan comparison table: docs/pricing-plans.md
"""

from __future__ import annotations

from dataclasses import asdict, dataclass
from typing import Any, Dict, Optional

# Bump when changing trial limits (stored in trial_usage.json for debugging).
PLAN_CONFIG_VERSION = 3

# Lemon checkout — Live PhotoPick ($19 launch)
# Test checkout: https://everflow-creative.lemonsqueezy.com/checkout/buy/974bf8eb-c43a-44e4-82c1-152b11c4fed8
PURCHASE_URL = "https://everflow-creative.lemonsqueezy.com/checkout/buy/27f94d9d-bbbe-482c-b226-5a43271f94eb"

# Dev-only key for testing licensed mode locally (remove or gate in production builds).
DEV_LICENSE_KEY = "PHOTOPICK-DEV-LICENSE"


@dataclass(frozen=True)
class PlanLimits:
    max_projects: Optional[int]
    max_photos_per_project: Optional[int]
    quality_rescan_max_per_project: Optional[int]  # manual force rescan; None = unlimited
    batch_rename_enabled: bool
    batch_delete_enabled: bool
    defect_detection_enabled: bool  # soft-focus / camera-shake only
    exposure_detection_enabled: bool  # histogram + overexposed/underexposed verdict
    editing_enabled: bool  # crop + straighten
    export_enabled: bool

    def to_dict(self) -> Dict[str, Any]:
        return asdict(self)


TRIAL = PlanLimits(
    max_projects=1,
    max_photos_per_project=100,
    quality_rescan_max_per_project=None,
    batch_rename_enabled=False,
    batch_delete_enabled=True,
    defect_detection_enabled=False,
    exposure_detection_enabled=False,
    editing_enabled=False,
    export_enabled=False,
)

LICENSED = PlanLimits(
    max_projects=None,
    max_photos_per_project=None,
    quality_rescan_max_per_project=None,
    batch_rename_enabled=True,
    batch_delete_enabled=True,
    defect_detection_enabled=True,
    exposure_detection_enabled=True,
    editing_enabled=True,
    export_enabled=True,
)


def limits_for_mode(mode: str) -> PlanLimits:
    return LICENSED if mode == "licensed" else TRIAL
