"""Celery task: ночной cross-load ETL tradein.houses → gendesign.newbuilding_listings.

Расписание: 03:30 МСК (hardcoded в beat_schedule, как cbr/poi/supply-layers).
Идемпотентен: UPSERT ON CONFLICT (source, ext_house_id).
Если TRADEIN_DATABASE_URL не задан → warn-log, возвращает {"disabled": True}.
"""

from __future__ import annotations

import logging

from app.services.etl.newbuilding_crossload import run_crossload
from app.workers.celery_app import celery_app

logger = logging.getLogger(__name__)


@celery_app.task(name="tasks.etl_newbuilding_crossload.etl_newbuilding_crossload")
def etl_newbuilding_crossload() -> dict:
    """Cross-load tradein.houses → gendesign.newbuilding_listings (#976).

    Вызывается beat'ом в 03:30 МСК и вручную через POST /api/v1/admin/scrape/newbuilding-crossload.
    """
    logger.info("task etl_newbuilding_crossload: start")
    result = run_crossload()
    logger.info("task etl_newbuilding_crossload: done — %s", result)
    return result
