from __future__ import annotations

from InvestmentWebsite.offers.sources import ALL_SOURCES

ALLOWED_SOURCES = set(ALL_SOURCES)
ALLOWED_CURRENCIES = {"PLN", "EUR", "AED", "unknown"}


def validate_canonical_offer(offer: dict) -> tuple[bool, list[str]]:
    errors = []

    source = ((offer.get("source") or {}).get("platform") or "").strip()
    if source not in ALLOWED_SOURCES:
        errors.append("source.platform")

    offer_id = ((offer.get("identity") or {}).get("offer_id") or "").strip()
    if not offer_id:
        errors.append("identity.offer_id")

    title = ((offer.get("listing") or {}).get("title") or "").strip()
    if not title:
        errors.append("listing.title")

    currency = ((offer.get("pricing") or {}).get("currency") or "").strip()
    if currency not in ALLOWED_CURRENCIES:
        errors.append("pricing.currency")

    gallery = (offer.get("media") or {}).get("gallery")
    if not isinstance(gallery, list):
        errors.append("media.gallery")

    return (len(errors) == 0), errors
