"""One-off seed: registers translation_keys English source_text and hi/mr/hinglish
translation_values for Yup form-validation messages across ~17 pages that were
previously hardcoded (never routed through i18n). Two namespaces:
  - "app": feature-page validation messages (all pages except auth screens)
  - "common": auth screens (login/forgot-password/reset-password/sign-up),
    which use the statically-bundled "common" namespace per src/i18n/index.ts

Usage: docker compose exec api python seed_translations_yup_validation.py
"""
import asyncio
import uuid
from datetime import datetime, timezone

from sqlalchemy import text
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine

from ams.core.config import settings

# key -> (namespace, english, hi, mr, hinglish)
VALIDATION = {
    "assets.appreciation.err.asset": ("app", "Select an asset", "एक asset चुनें", "एक asset निवडा", "Ek asset select karein"),
    "assets.appreciation.err.date": ("app", "Date is required", "तिथि आवश्यक है", "तारीख आवश्यक आहे", "Date zaroori hai"),
    "assets.appreciation.err.higherThanCurrent": ("app", "An appreciation must be higher than the current value — to write a value down, use Asset Revaluation instead", "एक appreciation मौजूदा value से अधिक होना चाहिए — value घटाने के लिए इसके बजाय Asset Revaluation का उपयोग करें", "एक appreciation सध्याच्या value पेक्षा जास्त असणे आवश्यक आहे — value कमी करण्यासाठी त्याऐवजी Asset Revaluation वापरा", "Appreciation current value se zyada hona chahiye — value kam karne ke liye Asset Revaluation use karein"),
    "assets.appreciation.err.valueNumber": ("app", "New value must be a number", "नई value एक संख्या होनी चाहिए", "नवीन value एक संख्या असणे आवश्यक आहे", "Nayi value ek number honi chahiye"),
    "assets.appreciation.err.valuePositive": ("app", "New value must be positive", "नई value धनात्मक होनी चाहिए", "नवीन value सकारात्मक असणे आवश्यक आहे", "Nayi value positive honi chahiye"),
    "assets.appreciation.err.valueRequired": ("app", "New value is required", "नई value आवश्यक है", "नवीन value आवश्यक आहे", "Nayi value zaroori hai"),
    "assets.create.err.assetClass": ("app", "Asset Class is required", "Asset Class आवश्यक है", "Asset Class आवश्यक आहे", "Asset Class zaroori hai"),
    "assets.create.err.fundingSource": ("app", "Funding Source is required", "Funding Source आवश्यक है", "Funding Source आवश्यक आहे", "Funding Source zaroori hai"),
    "assets.create.err.location": ("app", "Location is required", "Location आवश्यक है", "Location आवश्यक आहे", "Location zaroori hai"),
    "assets.queue.err.acquisitionDate": ("app", "Acquisition date is required", "Acquisition date आवश्यक है", "Acquisition date आवश्यक आहे", "Acquisition date zaroori hai"),
    "assets.queue.err.mustBeNumber": ("app", "Must be a number", "एक संख्या होनी चाहिए", "एक संख्या असणे आवश्यक आहे", "Ek number hona chahiye"),
    "assets.queue.err.mustBePositive": ("app", "Must be positive", "धनात्मक होना चाहिए", "सकारात्मक असणे आवश्यक आहे", "Positive hona chahiye"),
    "assets.register.err.costNumber": ("app", "Acquisition cost must be a number", "Acquisition cost एक संख्या होनी चाहिए", "Acquisition cost एक संख्या असणे आवश्यक आहे", "Acquisition cost ek number honi chahiye"),
    "assets.register.err.costPositive": ("app", "Acquisition cost must be greater than 0", "Acquisition cost 0 से अधिक होनी चाहिए", "Acquisition cost 0 पेक्षा जास्त असणे आवश्यक आहे", "Acquisition cost 0 se zyada honi chahiye"),
    "assets.register.err.costRequired": ("app", "Acquisition cost is required", "Acquisition cost आवश्यक है", "Acquisition cost आवश्यक आहे", "Acquisition cost zaroori hai"),
    "assets.register.err.deferredNegative": ("app", "Deferred revenue balance cannot be negative", "Deferred revenue balance ऋणात्मक नहीं हो सकता", "Deferred revenue balance ऋणात्मक असू शकत नाही", "Deferred revenue balance negative nahi ho sakta"),
    "assets.register.err.deferredNumber": ("app", "Deferred revenue balance must be a number", "Deferred revenue balance एक संख्या होनी चाहिए", "Deferred revenue balance एक संख्या असणे आवश्यक आहे", "Deferred revenue balance ek number honi chahiye"),
    "assets.register.err.name": ("app", "Asset Name is required", "Asset Name आवश्यक है", "Asset Name आवश्यक आहे", "Asset Name zaroori hai"),
    "assets.register.err.usefulLifeNumber": ("app", "Useful life override must be a number", "Useful life override एक संख्या होनी चाहिए", "Useful life override एक संख्या असणे आवश्यक आहे", "Useful life override ek number honi chahiye"),
    "assets.register.err.usefulLifePositive": ("app", "Useful life override must be positive", "Useful life override धनात्मक होनी चाहिए", "Useful life override सकारात्मक असणे आवश्यक आहे", "Useful life override positive honi chahiye"),
    "assets.revaluation.err.asset": ("app", "Select an asset", "एक asset चुनें", "एक asset निवडा", "Ek asset select karein"),
    "assets.revaluation.err.date": ("app", "Revaluation date is required", "Revaluation date आवश्यक है", "Revaluation date आवश्यक आहे", "Revaluation date zaroori hai"),
    "assets.revaluation.err.method": ("app", "Revaluation method is required", "Revaluation method आवश्यक है", "Revaluation method आवश्यक आहे", "Revaluation method zaroori hai"),
    "assets.revaluation.err.valueNumber": ("app", "Proposed value must be a number", "Proposed value एक संख्या होनी चाहिए", "Proposed value एक संख्या असणे आवश्यक आहे", "Proposed value ek number honi chahiye"),
    "assets.revaluation.err.valuePositive": ("app", "Proposed value must be positive", "Proposed value धनात्मक होनी चाहिए", "Proposed value सकारात्मक असणे आवश्यक आहे", "Proposed value positive honi chahiye"),
    "assets.revaluation.err.valueRequired": ("app", "Proposed adjusted value is required", "Proposed adjusted value आवश्यक है", "Proposed adjusted value आवश्यक आहे", "Proposed adjusted value zaroori hai"),
    "auth.validation.acceptPrivacy": ("common", "You must accept the Privacy Policy to register", "पंजीकरण के लिए आपको Privacy Policy स्वीकार करनी होगी", "नोंदणीसाठी तुम्हाला Privacy Policy स्वीकारावी लागेल", "Register karne ke liye Privacy Policy accept karna zaroori hai"),
    "auth.validation.acceptTerms": ("common", "You must accept the Terms & Conditions to register", "पंजीकरण के लिए आपको Terms & Conditions स्वीकार करनी होंगी", "नोंदणीसाठी तुम्हाला Terms &amp; Conditions स्वीकाराव्या लागतील", "Register karne ke liye Terms &amp; Conditions accept karna zaroori hai"),
    "auth.validation.confirmPasswordMatch": ("common", "Passwords do not match", "पासवर्ड मेल नहीं खाते", "पासवर्ड जुळत नाहीत", "Passwords match nahi ho rahe"),
    "auth.validation.confirmPasswordRequired": ("common", "Confirm New Password is required", "Confirm New Password आवश्यक है", "Confirm New Password आवश्यक आहे", "Confirm New Password zaroori hai"),
    "auth.validation.firstNameRequired": ("common", "First name is required", "First name आवश्यक है", "First name आवश्यक आहे", "First name zaroori hai"),
    "auth.validation.forgotEmailFormat": ("common", "Please enter a valid email address", "कृपया एक मान्य email address दर्ज करें", "कृपया वैध email address टाका", "Kripya ek valid email address daalein"),
    "auth.validation.forgotEmailRequired": ("common", "Email address is required", "Email address आवश्यक है", "Email address आवश्यक आहे", "Email address zaroori hai"),
    "auth.validation.lastNameRequired": ("common", "Last name is required", "Last name आवश्यक है", "Last name आवश्यक आहे", "Last name zaroori hai"),
    "auth.validation.loginEmailFormat": ("common", "Please enter a valid email address.", "कृपया एक मान्य email address दर्ज करें।", "कृपया वैध email address टाका.", "Kripya ek valid email address daalein."),
    "auth.validation.loginEmailRequired": ("common", "Email is required.", "Email आवश्यक है।", "Email आवश्यक आहे.", "Email zaroori hai."),
    "auth.validation.loginPasswordMax": ("common", "Password must not exceed 32 characters.", "Password 32 characters से अधिक नहीं होना चाहिए।", "Password 32 characters पेक्षा जास्त नसावा.", "Password 32 characters se zyada nahi hona chahiye."),
    "auth.validation.loginPasswordMin": ("common", "Password must be at least 6 characters.", "Password कम से कम 6 characters का होना चाहिए।", "Password किमान 6 characters चा असावा.", "Password kam se kam 6 characters ka hona chahiye."),
    "auth.validation.loginPasswordRequired": ("common", "Password is required.", "Password आवश्यक है।", "Password आवश्यक आहे.", "Password zaroori hai."),
    "auth.validation.mobileFormat": ("common", "Please enter a valid mobile number (minimum 10 digits)", "कृपया एक मान्य mobile number दर्ज करें (न्यूनतम 10 अंक)", "कृपया वैध mobile number टाका (किमान 10 अंक)", "Kripya ek valid mobile number daalein (kam se kam 10 digits)"),
    "auth.validation.mobileRequired": ("common", "Mobile number is required", "Mobile number आवश्यक है", "Mobile number आवश्यक आहे", "Mobile number zaroori hai"),
    "auth.validation.newPasswordMin": ("common", "Password must be at least 8 characters long", "Password कम से कम 8 characters का होना चाहिए", "Password किमान 8 characters चा असावा", "Password kam se kam 8 characters ka hona chahiye"),
    "auth.validation.newPasswordRequired": ("common", "New Password is required", "New Password आवश्यक है", "New Password आवश्यक आहे", "New Password zaroori hai"),
    "auth.validation.signupConfirmPasswordMatch": ("common", "Passwords do not match", "पासवर्ड मेल नहीं खाते", "पासवर्ड जुळत नाहीत", "Passwords match nahi ho rahe"),
    "auth.validation.signupConfirmPasswordRequired": ("common", "Confirm password is required", "Confirm password आवश्यक है", "Confirm password आवश्यक आहे", "Confirm password zaroori hai"),
    "auth.validation.signupEmailFormat": ("common", "Please enter a valid email address (e.g. user@domain.com)", "कृपया एक मान्य email address दर्ज करें (उदा. user@domain.com)", "कृपया वैध email address टाका (उदा. user@domain.com)", "Kripya ek valid email address daalein (jaise user@domain.com)"),
    "auth.validation.signupEmailRequired": ("common", "Email address is required", "Email address आवश्यक है", "Email address आवश्यक आहे", "Email address zaroori hai"),
    "auth.validation.signupPasswordMin": ("common", "Password must be at least 8 characters long", "Password कम से कम 8 characters का होना चाहिए", "Password किमान 8 characters चा असावा", "Password kam se kam 8 characters ka hona chahiye"),
    "auth.validation.signupPasswordRequired": ("common", "Password is required", "Password आवश्यक है", "Password आवश्यक आहे", "Password zaroori hai"),
    "auth.validation.tenant": ("common", "Tenant is required.", "Tenant आवश्यक है।", "Tenant आवश्यक आहे.", "Tenant zaroori hai."),
    "custody-assign.validation.assetRequired": ("app", "Asset is required.", "Asset आवश्यक है।", "Asset आवश्यक आहे.", "Asset zaroori hai."),
    "custody-assign.validation.custodianRequired": ("app", "Custodian is required.", "Custodian आवश्यक है।", "Custodian आवश्यक आहे.", "Custodian zaroori hai."),
    "department-masters.validation.name": ("app", "Department name is required", "Department name आवश्यक है", "Department name आवश्यक आहे", "Department name zaroori hai"),
    "generic-masters.validation.code": ("app", "Code is required", "Code आवश्यक है", "Code आवश्यक आहे", "Code zaroori hai"),
    "generic-masters.validation.name": ("app", "Name is required", "Name आवश्यक है", "Name आवश्यक आहे", "Name zaroori hai"),
    "master-data.alert.errChannel": ("app", "Select at least one channel", "कम से कम एक channel चुनें", "किमान एक channel निवडा", "Kam se kam ek channel select karein"),
    "master-data.alert.errCode": ("app", "Code is required", "Code आवश्यक है", "Code आवश्यक आहे", "Code zaroori hai"),
    "master-data.alert.errName": ("app", "Name is required", "Name आवश्यक है", "Name आवश्यक आहे", "Name zaroori hai"),
    "master-data.template.errCode": ("app", "Code is required", "Code आवश्यक है", "Code आवश्यक आहे", "Code zaroori hai"),
    "master-data.template.errName": ("app", "Name is required", "Name आवश्यक है", "Name आवश्यक आहे", "Name zaroori hai"),
    "master-lists.validation.assetClassId": ("app", "Asset Class is required", "Asset Class आवश्यक है", "Asset Class आवश्यक आहे", "Asset Class zaroori hai"),
    "master-lists.validation.bankIfsc": ("app", "Invalid IFSC (11 chars)", "अमान्य IFSC (11 अक्षर)", "अवैध IFSC (11 अक्षरे)", "Invalid IFSC (11 chars)"),
    "master-lists.validation.categoryCode": ("app", "Category Code is required", "Category Code आवश्यक है", "Category Code आवश्यक आहे", "Category Code zaroori hai"),
    "master-lists.validation.categoryId": ("app", "Asset Category is required", "Asset Category आवश्यक है", "Asset Category आवश्यक आहे", "Asset Category zaroori hai"),
    "master-lists.validation.categoryName": ("app", "Category Name is required", "Category Name आवश्यक है", "Category Name आवश्यक आहे", "Category Name zaroori hai"),
    "master-lists.validation.classCode": ("app", "Asset Class Code is required", "Asset Class Code आवश्यक है", "Asset Class Code आवश्यक आहे", "Asset Class Code zaroori hai"),
    "master-lists.validation.className": ("app", "Asset Class Name is required", "Asset Class Name आवश्यक है", "Asset Class Name आवश्यक आहे", "Asset Class Name zaroori hai"),
    "master-lists.validation.contactEmailFormat": ("app", "Invalid email address", "अमान्य email address", "अवैध email address", "Invalid email address"),
    "master-lists.validation.contactEmailLength": ("app", "Email too long", "Email बहुत लंबा है", "Email खूप मोठा आहे", "Email bahut lamba hai"),
    "master-lists.validation.contactPhone": ("app", "Invalid phone number", "अमान्य phone number", "अवैध phone number", "Invalid phone number"),
    "master-lists.validation.docCode": ("app", "Document Code is required", "Document Code आवश्यक है", "Document Code आवश्यक आहे", "Document Code zaroori hai"),
    "master-lists.validation.docName": ("app", "Document Name is required", "Document Name आवश्यक है", "Document Name आवश्यक आहे", "Document Name zaroori hai"),
    "master-lists.validation.gstin": ("app", "Invalid GSTIN (15 chars)", "अमान्य GSTIN (15 अक्षर)", "अवैध GSTIN (15 अक्षरे)", "Invalid GSTIN (15 chars)"),
    "master-lists.validation.locCode": ("app", "Location Code is required", "Location Code आवश्यक है", "Location Code आवश्यक आहे", "Location Code zaroori hai"),
    "master-lists.validation.locLevel": ("app", "Level is required", "Level आवश्यक है", "Level आवश्यक आहे", "Level zaroori hai"),
    "master-lists.validation.locName": ("app", "Location Name is required", "Location Name आवश्यक है", "Location Name आवश्यक आहे", "Location Name zaroori hai"),
    "master-lists.validation.pan": ("app", "Invalid PAN (10 chars)", "अमान्य PAN (10 अक्षर)", "अवैध PAN (10 अक्षरे)", "Invalid PAN (10 chars)"),
    "master-lists.validation.subCategoryCode": ("app", "Sub-Category Code is required", "Sub-Category Code आवश्यक है", "Sub-Category Code आवश्यक आहे", "Sub-Category Code zaroori hai"),
    "master-lists.validation.subCategoryName": ("app", "Sub-Category Name is required", "Sub-Category Name आवश्यक है", "Sub-Category Name आवश्यक आहे", "Sub-Category Name zaroori hai"),
    "master-lists.validation.vendorCode": ("app", "Vendor Code is required", "Vendor Code आवश्यक है", "Vendor Code आवश्यक आहे", "Vendor Code zaroori hai"),
    "master-lists.validation.vendorName": ("app", "Vendor Name is required", "Vendor Name आवश्यक है", "Vendor Name आवश्यक आहे", "Vendor Name zaroori hai"),
    "master-lists.validation.vendorType": ("app", "Vendor Type is required", "Vendor Type आवश्यक है", "Vendor Type आवश्यक आहे", "Vendor Type zaroori hai"),
    "org-units-add.validation.clientType": ("app", "Client Type is required.", "Client Type आवश्यक है।", "Client Type आवश्यक आहे.", "Client Type zaroori hai."),
    "org-units-add.validation.name": ("app", "Unit Name is required.", "Unit Name आवश्यक है।", "Unit Name आवश्यक आहे.", "Unit Name zaroori hai."),
    "org-units-add.validation.ouType": ("app", "Org Unit Type is required.", "Org Unit Type आवश्यक है।", "Org Unit Type आवश्यक आहे.", "Org Unit Type zaroori hai."),
    "roles-create.validation.roleName": ("app", "Role Name is required.", "Role Name आवश्यक है।", "Role Name आवश्यक आहे.", "Role Name zaroori hai."),
    "roles-edit.validation.description": ("app", "Description is required.", "Description आवश्यक है।", "Description आवश्यक आहे.", "Description zaroori hai."),
    "roles-edit.validation.roleName": ("app", "Role Name is required.", "Role Name आवश्यक है।", "Role Name आवश्यक आहे.", "Role Name zaroori hai."),
    "roles-edit.validation.status": ("app", "Status is required.", "Status आवश्यक है।", "Status आवश्यक आहे.", "Status zaroori hai."),
    "users-edit.validation.confirmPasswordMatch": ("app", "Passwords do not match.", "पासवर्ड मेल नहीं खाते।", "पासवर्ड जुळत नाहीत.", "Passwords match nahi ho rahe."),
    "users-edit.validation.confirmPasswordRequired": ("app", "Confirm the new password.", "नया password confirm करें।", "नवीन password confirm करा.", "Naya password confirm karein."),
    "users-edit.validation.emailFormat": ("app", "Please enter a valid email address.", "कृपया एक मान्य email address दर्ज करें।", "कृपया वैध email address टाका.", "Kripya ek valid email address daalein."),
    "users-edit.validation.emailRequired": ("app", "Email Address is required.", "Email Address आवश्यक है।", "Email Address आवश्यक आहे.", "Email Address zaroori hai."),
    "users-edit.validation.role": ("app", "Role is required.", "Role आवश्यक है।", "Role आवश्यक आहे.", "Role zaroori hai."),
    "users-edit.validation.status": ("app", "Status is required.", "Status आवश्यक है।", "Status आवश्यक आहे.", "Status zaroori hai."),
    "users-edit.validation.userName": ("app", "User Name is required.", "User Name आवश्यक है।", "User Name आवश्यक आहे.", "User Name zaroori hai."),
    "vendor-contracts.contracts.valContractNumber": ("app", "Contract Number is required", "Contract Number आवश्यक है", "Contract Number आवश्यक आहे", "Contract Number zaroori hai"),
    "vendor-contracts.contracts.valContractType": ("app", "Contract Type is required", "Contract Type आवश्यक है", "Contract Type आवश्यक आहे", "Contract Type zaroori hai"),
    "vendor-contracts.contracts.valEndDate": ("app", "End Date is required", "End Date आवश्यक है", "End Date आवश्यक आहे", "End Date zaroori hai"),
    "vendor-contracts.contracts.valMustBePositive": ("app", "Must be > 0", "0 से अधिक होना चाहिए", "0 पेक्षा जास्त असणे आवश्यक", "0 se zyada hona chahiye"),
    "vendor-contracts.contracts.valRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
    "vendor-contracts.contracts.valStartDate": ("app", "Start Date is required", "Start Date आवश्यक है", "Start Date आवश्यक आहे", "Start Date zaroori hai"),
    "vendor-contracts.contracts.valValue": ("app", "Value is required", "Value आवश्यक है", "Value आवश्यक आहे", "Value zaroori hai"),
    "vendor-contracts.contracts.valValueGreater": ("app", "Value must be greater than 0", "Value 0 से अधिक होनी चाहिए", "Value 0 पेक्षा जास्त असणे आवश्यक आहे", "Value 0 se zyada honi chahiye"),
    "vendor-contracts.contracts.valVendor": ("app", "Vendor is required", "Vendor आवश्यक है", "Vendor आवश्यक आहे", "Vendor zaroori hai"),
    "warranty.validation.descriptionRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
    "warranty.validation.endDateRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
    "warranty.validation.incidentDateRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
    "warranty.validation.insurerRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
    "warranty.validation.policyNumberRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
    "warranty.validation.policyTypeRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
    "warranty.validation.premiumMoreThanZero": ("app", "Must be > 0", "0 से अधिक होना चाहिए", "0 पेक्षा जास्त असणे आवश्यक", "0 se zyada hona chahiye"),
    "warranty.validation.premiumRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
    "warranty.validation.settledAmountMoreThanZero": ("app", "Must be > 0", "0 से अधिक होना चाहिए", "0 पेक्षा जास्त असणे आवश्यक", "0 se zyada hona chahiye"),
    "warranty.validation.settledAmountRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
    "warranty.validation.startDateRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
    "warranty.validation.sumInsuredMoreThanZero": ("app", "Must be > 0", "0 से अधिक होना चाहिए", "0 पेक्षा जास्त असणे आवश्यक", "0 se zyada hona chahiye"),
    "warranty.validation.sumInsuredRequired": ("app", "Required", "आवश्यक", "आवश्यक", "Required"),
}


async def seed_for_session(session: AsyncSession) -> tuple[int, int]:
    now = datetime.now(timezone.utc)
    keys_upserted = 0
    values_upserted = 0
    for key, (ns, en, hi, mr, hinglish) in VALIDATION.items():
        key_id = (await session.execute(
            text("SELECT id FROM translation_keys WHERE namespace = :ns AND key = :key"),
            {"ns": ns, "key": key},
        )).scalar_one_or_none()
        if key_id:
            await session.execute(
                text("UPDATE translation_keys SET source_text = :src WHERE id = :id"),
                {"src": en, "id": key_id},
            )
        else:
            key_id = str(uuid.uuid4())
            await session.execute(
                text("""INSERT INTO translation_keys (id, namespace, key, source_text, created_at)
                        VALUES (:id, :ns, :key, :src, :now)"""),
                {"id": key_id, "ns": ns, "key": key, "src": en, "now": now},
            )
            keys_upserted += 1

        for lang_code, value in (("hi", hi), ("mr", mr), ("hinglish", hinglish)):
            existing = (await session.execute(
                text("SELECT id FROM translation_values WHERE key_id = :kid AND language_code = :lc"),
                {"kid": key_id, "lc": lang_code},
            )).scalar_one_or_none()
            if existing:
                await session.execute(
                    text("UPDATE translation_values SET value = :val, updated_at = :now WHERE id = :id"),
                    {"val": value, "now": now, "id": existing},
                )
            else:
                await session.execute(
                    text("""INSERT INTO translation_values (id, key_id, language_code, value, updated_by, updated_at)
                            VALUES (:id, :kid, :lc, :val, NULL, :now)"""),
                    {"id": str(uuid.uuid4()), "kid": key_id, "lc": lang_code, "val": value, "now": now},
                )
                values_upserted += 1
    await session.commit()
    return keys_upserted, values_upserted


async def main() -> None:
    engine = create_async_engine(settings.DATABASE_URL, echo=False)
    Session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)

    async with Session() as session:
        tenants = (await session.execute(
            text("SELECT id::text AS id, slug FROM public.tenants WHERE status != 'archived'")
        )).fetchall()

    for tenant in tenants:
        schema = f"tenant_{tenant.id.replace('-', '_')}"
        async with Session() as session:
            await session.execute(text(f"SET search_path TO {schema}, public"))
            try:
                k, v = await seed_for_session(session)
                print(f"  seeded {k} new keys, {v} new values: {tenant.slug}")
            except Exception as exc:
                print(f"  SKIPPED {tenant.slug}: {exc}")
                await session.rollback()

    await engine.dispose()
    print(f"Done — {len(tenants)} tenant(s) processed, {len(VALIDATION)} validation keys.")


if __name__ == "__main__":
    asyncio.run(main())
