<?php

declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| Marketplace configuration
|--------------------------------------------------------------------------
|
| Values here are platform-wide defaults and operational limits. Anything a
| platform administrator is expected to tune per TLD, seller, listing type or
| plan lives in the database (see the `fees` and `plans` tables) rather than
| here -- see the marketplace rules in the product spec: fee percentages must
| never be hardcoded. The defaults below are the last-resort fallback used
| only when no database rule matches, so that a misconfigured environment
| fails loudly-but-safely rather than charging nothing.
|
*/

return [

    /*
    | The single currency every stored amount is denominated in. All monetary
    | columns are BIGINT minor units (e.g. cents) -- never floats.
    */
    'base_currency' => env('MARKETPLACE_BASE_CURRENCY', 'USD'),

    'fees' => [
        // Basis points: 1000 bps = 10.00%.
        'default_seller_commission_bps' => (int) env('MARKETPLACE_DEFAULT_SELLER_COMMISSION_BPS', 1000),
        'default_buyer_fee_bps' => (int) env('MARKETPLACE_DEFAULT_BUYER_FEE_BPS', 0),
    ],

    'verification' => [
        // The DNS TXT host sellers are asked to create, e.g. _domainsansar.example.com
        'txt_host' => env('DOMAIN_VERIFICATION_TXT_HOST', '_domainsansar'),

        // The TXT value prefix. Full record: <prefix>=<token>
        'txt_prefix' => 'domainsansar-verification',

        'token_ttl_hours' => (int) env('DOMAIN_VERIFICATION_TOKEN_TTL_HOURS', 168),
        'max_attempts' => (int) env('DOMAIN_VERIFICATION_MAX_ATTEMPTS', 25),

        /*
        | A single resolver can be poisoned or stale. We query several
        | independent public resolvers and require a quorum of them to observe
        | the same token before ownership is accepted.
        */
        'resolvers' => array_values(array_filter(array_map(
            'trim',
            explode(',', (string) env('DOMAIN_VERIFICATION_RESOLVERS', '1.1.1.1,8.8.8.8,9.9.9.9'))
        ))),
        'resolver_quorum' => (int) env('DOMAIN_VERIFICATION_RESOLVER_QUORUM', 2),

        // Minimum wait between seller-triggered verification checks, in seconds.
        'recheck_cooldown_seconds' => 60,
    ],

    'offers' => [
        'default_expiry_hours' => (int) env('OFFER_DEFAULT_EXPIRY_HOURS', 168),
        'min_amount_minor' => (int) env('OFFER_MIN_AMOUNT_MINOR', 100),
        // Hard ceiling to stop absurd offers poisoning analytics and notifications.
        'max_amount_minor' => 100_000_000_00,
        'max_negotiation_rounds' => 20,
    ],

    'payouts' => [
        /*
        | Funds are only eligible for release after the transfer is
        | independently confirmed complete AND this hold period elapses, giving
        | a dispute window. A seller asserting "I transferred it" is never
        | sufficient on its own.
        */
        'hold_period_hours' => (int) env('PAYOUT_HOLD_PERIOD_HOURS', 72),
        'minimum_payout_minor' => 1000,
    ],

    'fraud' => [
        'max_offers_per_user_per_day' => (int) env('FRAUD_MAX_OFFERS_PER_USER_PER_DAY', 40),
        'max_listings_per_user_per_day' => (int) env('FRAUD_MAX_LISTINGS_PER_USER_PER_DAY', 100),
        // Failed logins from one IP before it is throttled harder.
        'login_attempt_threshold' => 5,
    ],

    'listing' => [
        'max_description_length' => 5000,
        'max_images_per_listing' => 6,
    ],
];
