<?php

namespace App\Http\Controllers\v2026\v1;

use App\Http\Controllers\Controller;
use App\Services\V2026\V2026LegacyBridge;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Validator;

class V2026ApiController extends Controller
{
    private function ok($message, array $data = [], $httpStatus = 200)
    {
        return Response::json([
            'status' => $httpStatus >= 200 && $httpStatus < 300,
            'message' => $message,
            'data' => empty($data) ? (object) [] : $data,
        ], $httpStatus);
    }

    private function created($message, array $data = [])
    {
        return $this->ok($message, $data, 201);
    }

    private function validationErrorResponse($validator)
    {
        return Response::json([
            'status' => false,
            'message' => 'Validation error',
            'errors' => $validator->errors(),
        ], 422);
    }

    /**
     * @param  array<string, mixed>  $postBody
     * @param  array{client_paginate?: bool, server_meta?: array|null}  $respondOptions
     */
    private function v2019Post(Request $request, string $controllerClass, string $method, array $postBody, array $respondOptions = []): JsonResponse
    {
        try {
            $raw = V2026LegacyBridge::invoke($request, $controllerClass, $method, $postBody);

            return V2026LegacyBridge::respondFromLegacy($raw, $request, $respondOptions);
        } catch (\Throwable $e) {
            Log::error($e->getMessage(), ['exception' => $e]);

            return V2026LegacyBridge::jsonFromEnvelope(false, 'Service temporarily unavailable', new \stdClass(), 500);
        }
    }

    public function authSessionValidate(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Session is valid',
            'data' => [
                'is_valid' => true,
                'user_id' => null,
                'session_id' => $request->header('X-Session-Id'),
            ],
        ], 200);
    }

    public function configApp(Request $request)
    {
        return $this->ok('Configuration retrieved successfully', [
            'meta' => [
                'version_hash' => 'v2026-dev',
                'last_updated' => gmdate('c'),
            ],
            'maintenance' => [
                'is_active' => false,
                'message' => null,
                'estimated_end' => null,
            ],
            'version_control' => [
                'min_version' => '0.0.0',
                'latest_version' => '0.0.0',
                'store_url' => null,
            ],
            'feature_flags' => [
                'enable_new_ui' => true,
            ],
        ]);
    }

    public function configStaticPages(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Static pages config fetched successfully',
            'data' => [
                'terms_url' => null,
                'privacy_url' => null,
                'about_url' => null,
                'methodology_url' => null,
            ],
        ], 200);
    }

    public function configHelp(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Help config fetched successfully',
            'data' => (object) [],
        ], 200);
    }

    public function homeExplore(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Home explore fetched successfully',
            'data' => [
                'banner' => [
                    'banner_id' => 1,
                    'image_url' => 'https://dummyimage.com/600x300/dbdbdb/000000&text=Single+Banner+Image',
                    'redirect_link' => 'https://example.com/promotion',
                ],
                'all_markets' => [
                    [
                        'market_id' => 1,
                        'market' => 'Ferrous',
                        'market_icon' => 'https://example.com/icons/ferrous.png',
                        'market_link' => 'https://example.com/market/ferrous',
                    ],
                    [
                        'market_id' => 2,
                        'market' => 'Non-Ferrous',
                        'market_icon' => 'https://example.com/icons/non-ferrous.png',
                        'market_link' => 'https://example.com/market/non-ferrous',
                    ],
                    [
                        'market_id' => 3,
                        'market' => 'Coal & Energy',
                        'market_icon' => 'https://example.com/icons/coal.png',
                        'market_link' => 'https://example.com/market/coal-energy',
                    ],
                    [
                        'market_id' => 4,
                        'market' => 'Scrap',
                        'market_icon' => 'https://example.com/icons/scrap.png',
                        'market_link' => 'https://example.com/market/scrap',
                    ],
                    [
                        'market_id' => 5,
                        'market' => 'Agriculture',
                        'market_icon' => 'https://example.com/icons/agri.png',
                        'market_link' => 'https://example.com/market/agriculture',
                    ],
                    [
                        'market_id' => 6,
                        'market' => 'Logistics',
                        'market_icon' => 'https://example.com/icons/logistics.png',
                        'market_link' => 'https://example.com/market/logistics',
                    ],
                    [
                        'market_id' => 7,
                        'market' => 'Futures',
                        'market_icon' => 'https://example.com/icons/futures.png',
                        'market_link' => 'https://example.com/market/futures',
                    ],
                    [
                        'market_id' => 8,
                        'market' => 'Statistics',
                        'market_icon' => 'https://example.com/icons/stats.png',
                        'market_link' => 'https://example.com/market/statistics',
                    ],
                ],
                'flash_news' => [
                    'view_all_link' => 'https://example.com/news/all',
                    'items' => [
                        [
                            'news_id' => 101,
                            'news_type' => 'Intel',
                            'title' => "Global iron ore exports show divergent trends in CY'25; India shipment falls 30% YoY",
                            'published_date' => '29 Jan 2026, 15:51 IST',
                            'read_time' => '3 min read',
                            'thumbnail_image' => 'https://dummyimage.com/400x250/000/fff&text=News+Image',
                            'detail_link' => 'https://example.com/news/global-iron-ore-trends',
                        ],
                        [
                            'news_id' => 102,
                            'news_type' => 'Insight',
                            'title' => 'Coal prices stabilize as winter demand cools down across Asia',
                            'published_date' => '30 Jan 2026, 10:20 IST',
                            'read_time' => '5 min read',
                            'thumbnail_image' => 'https://dummyimage.com/400x250/000/fff&text=News+Image+2',
                            'detail_link' => 'https://example.com/news/coal-price-update',
                        ],
                        [
                            'news_id' => 103,
                            'news_type' => 'Insight',
                            'title' => 'Metcoke prices stabilize as winter demand cools down across Africa',
                            'published_date' => '31 Jan 2026, 10:20 IST',
                            'read_time' => '5 min read',
                            'thumbnail_image' => 'https://dummyimage.com/400x250/000/fff&text=News+Image+2',
                            'detail_link' => 'https://example.com/news/coal-price-edit',
                        ],
                    ],
                ],
                'prices' => [
                    'view_all_link' => 'https://example.com/prices/all',
                    'items' => [
                        [
                            'assesment_id' => 1,
                            'commodity' => 'Iron Ore',
                            'sub_commodity' => 'fines/lumps',
                            'price' => '7,250',
                            'currency' => 'INR',
                            'trade_type' => 'domestic',
                            'change' => '+150',
                            'change_percent' => '2.1%',
                            'arrow' => 'up',
                            'title' => 'Iron Ore Lumps, Odisha Index',
                            'size_grade' => '5-18mm, Fe 60%',
                            'published_date' => '2026-02-01',
                            'frequency' => 'Daily',
                        ],
                        [
                            'assesment_id' => 2,
                            'commodity' => 'coal',
                            'sub_commodity' => 'Coking Coal',
                            'price' => '98.50',
                            'currency' => 'USD',
                            'trade_type' => 'global',
                            'change' => '-2.30',
                            'change_percent' => '2.3%',
                            'arrow' => 'down',
                            'title' => 'Iron Ore Fines, CFR China',
                            'size_grade' => '62/63% Fe (India Origin)',
                            'published_date' => '2026-02-01',
                            'frequency' => 'Weekly',
                        ],
                    ],
                ],
                'reports' => [
                    'view_all_link' => 'https://example.com/reports/all',
                    'items' => [
                        [
                            'report_id' => 501,
                            'title' => 'India Iron Ore Market Outlook 2026',
                            'detail_link' => 'https://example.com/report/iron-ore-2026',
                        ],
                        [
                            'report_id' => 502,
                            'title' => 'Steel Industry Annual Review',
                            'detail_link' => 'https://example.com/report/steel-annual',
                        ],
                        [
                            'report_id' => 503,
                            'title' => 'Coal Market Monthly Jan 2026',
                            'detail_link' => 'https://example.com/report/coal-monthly',
                        ],
                    ],
                ],
                'analyst_corner' => [
                    'view_all_link' => 'https://example.com/analyst/all',
                    'items' => [
                        [
                            'news_id' => 1,
                            'news_type' => 'Insight',
                            'title' => 'Iron ore prices likely to stay range-bound in Q1 FY27 amid weak...',
                            'published_date' => '29 Jan 16:00 IST',
                            'read_time' => '4 min read',
                            'thumbnail_image' => 'https://example.com/images/analyst1.png',
                            'detail_link' => 'https://example.com/analyst/iron-ore-prices',
                        ],
                        [
                            'news_id' => 2,
                            'news_type' => 'Intel',
                            'title' => 'Steel exports from India may rise 15% in FY26 on global demand...',
                            'published_date' => '28 Jan 10:30 IST',
                            'read_time' => '5 min read',
                            'thumbnail_image' => 'https://example.com/images/analyst2.png',
                            'detail_link' => 'https://example.com/analyst/steel-exports',
                        ],
                        [
                            'news_id' => 3,
                            'news_type' => 'Intel',
                            'title' => 'Copper supply deficit to widen in 2026; prices may test $10,500/t',
                            'published_date' => '27 Jan 14:15 IST',
                            'read_time' => '3 min read',
                            'thumbnail_image' => 'https://example.com/images/analyst3.png',
                            'detail_link' => 'https://example.com/analyst/copper-supply',
                        ],
                        [
                            'news_id' => 4,
                            'news_type' => 'Insight',
                            'title' => 'Domestic coal production on track to hit 1 BT target by FY27',
                            'published_date' => '26 Jan 09:45 IST',
                            'read_time' => '4 min read',
                            'thumbnail_image' => 'https://example.com/images/analyst4.png',
                            'detail_link' => 'https://example.com/analyst/coal-production',
                        ],
                    ],
                ],
                'industry' => [
                    'view_all_link' => 'https://example.com/industry/all',
                    'items' => [
                        [
                            'industry_id' => 1,
                            'industry_name' => 'Steel',
                            'assessment_count' => '142 Assessments',
                            'detail_link' => 'https://example.com/industry/steel',
                        ],
                        [
                            'industry_id' => 2,
                            'industry_name' => 'Mining',
                            'assessment_count' => '86 Assessments',
                            'detail_link' => 'https://example.com/industry/mining',
                        ],
                        [
                            'industry_id' => 3,
                            'industry_name' => 'Power',
                            'assessment_count' => '54 Assessments',
                            'detail_link' => 'https://example.com/industry/power',
                        ],
                        [
                            'industry_id' => 4,
                            'industry_name' => 'Auto',
                            'assessment_count' => '20 Assessments',
                            'detail_link' => 'https://example.com/industry/auto',
                        ],
                        [
                            'industry_id' => 5,
                            'industry_name' => 'Construction',
                            'assessment_count' => '25 Assessments',
                            'redirect_link' => 'https://example.com/industry/construction',
                        ],
                    ],
                ],
                'daily_mover' => [
                    'view_all_link' => 'https://example.com/movers/all',
                    'items' => [
                        'top_gainers' => [
                            'list' => [
                                [
                                    'assessment_id' => 101,
                                    'commodity' => 'Iron Ore',
                                    'sub_commodity' => 'fines/lumps',
                                    'currency' => 'USD',
                                    'trade_type' => 'global',
                                    'size_grade' => '5-18mm, F...',
                                    'price' => '₹7,250',
                                    'title' => 'Iron Ore Lumps, Odisha Index',
                                    'change' => '+₹150',
                                    'change_percent' => '2.1%',
                                    'arrow' => 'up',
                                    'detail_link' => 'https://example.com/details/101',
                                ],
                                [
                                    'assessment_id' => 102,
                                    'commodity' => 'coal',
                                    'sub_commodity' => 'Coking Coal',
                                    'currency' => 'INR',
                                    'trade_type' => 'domestic',
                                    'size_grade' => 'CSN 9.0, ...',
                                    'price' => '$220',
                                    'title' => 'Met Coke, Raipur Index',
                                    'change' => '+$3.96',
                                    'change_percent' => '1.8%',
                                    'arrow' => 'up',
                                    'detail_link' => 'https://example.com/details/102',
                                ],
                                [
                                    'assessment_id' => 103,
                                    'commodity' => 'steel',
                                    'sub_commodity' => 'Rebar',
                                    'currency' => 'INR',
                                    'trade_type' => 'domestic',
                                    'size_grade' => '2mm, AS...',
                                    'price' => '₹1,42,500',
                                    'title' => 'billet, India Index',
                                    'change' => '+₹1,500',
                                    'change_percent' => '1.1%',
                                    'arrow' => 'up',
                                    'detail_link' => 'https://example.com/details/103',
                                ],
                            ],
                        ],
                        'top_losers' => [
                            'list' => [
                                [
                                    'assessment_id' => 201,
                                    'commodity' => 'grains',
                                    'sub_commodity' => 'Soybean',
                                    'currency' => 'INR',
                                    'trade_type' => 'domestic',
                                    'size_grade' => 'FAQ Grad...',
                                    'price' => '₹4,250',
                                    'title' => 'Rice, chhattisgarh india market',
                                    'change' => '-₹160',
                                    'change_percent' => '3.6%',
                                    'arrow' => 'down',
                                    'detail_link' => 'https://example.com/details/201',
                                ],
                                [
                                    'assessment_id' => 202,
                                    'commodity' => 'Scrap & metallics',
                                    'sub_commodity' => 'Sponge Iron',
                                    'currency' => 'USD',
                                    'trade_type' => 'global',
                                    'size_grade' => 'Fe 86%, ...',
                                    'price' => '₹24,800',
                                    'title' => 'melting scale, chhattisgarh india Index',
                                    'change' => '-₹580',
                                    'change_percent' => '2.3%',
                                    'arrow' => 'down',
                                    'detail_link' => 'https://example.com/details/202',
                                ],
                                [
                                    'assessment_id' => 203,
                                    'commodity' => 'Ferro Alloy',
                                    'sub_commodity' => 'Ferro Chrome',
                                    'currency' => 'INR',
                                    'trade_type' => 'domestic',
                                    'size_grade' => '60-65%...',
                                    'price' => '₹82,000',
                                    'title' => 'Ferro Chrome, chhattisgarh india Index',
                                    'change' => '-₹8,200',
                                    'change_percent' => '9.1%',
                                    'arrow' => 'down',
                                    'detail_link' => 'https://example.com/details/203',
                                ],
                            ],
                        ],
                    ],
                ],
                'recently_viewed' => [
                    'view_all_link' => 'https://example.com/recently-viewed/all',
                    'items' => [
                        [
                            'assessment_id' => 111,
                            'commodity' => 'Iron Ore',
                            'sub_commodity' => 'fines/lumps',
                            'title' => 'Iron Ore Lumps, Odisha Index',
                            'size_grade' => '5-18mm, Fe 60% | Domestic',
                            'trade_type' => 'domestic',
                            'currency' => 'INR',
                            'price' => '₹7,250',
                            'change' => '+ ₹150 (2.1%)',
                            'change_percent' => '9.1%',
                            'arrow' => 'up',
                            'detail_link' => 'https://example.com/details/iron-ore-lumps',
                        ],
                        [
                            'assessment_id' => 112,
                            'commodity' => 'Iron Ore',
                            'sub_commodity' => 'fines/lumps',
                            'title' => 'Iron Ore Fines, CNF Qingdao',
                            'size_grade' => '62/63% Fe | Import',
                            'trade_type' => 'global',
                            'currency' => 'USD',
                            'price' => '$98.50',
                            'change' => '- $2.30 (2.3%)',
                            'change_percent' => '20.1%',
                            'arrow' => 'down',
                            'detail_link' => 'https://example.com/details/iron-ore-fines',
                        ],
                        [
                            'assessment_id' => 113,
                            'commodity' => 'Coal',
                            'sub_commodity' => 'Met Coke',
                            'title' => 'Met coake based market, Raipur',
                            'size_grade' => '22|mm Domestic',
                            'trade_type' => 'domestic',
                            'currency' => 'INR',
                            'price' => '₹24,800',
                            'change' => '+ ₹200 (0.8%)',
                            'change_percent' => '25.1%',
                            'arrow' => 'down',
                            'detail_link' => 'https://example.com/details/sponge-iron',
                        ],
                    ],
                ],
                'featured_events' => [
                    'view_all_link' => 'https://example.com/events/all',
                    'event' => [
                        'items' => [
                            [
                                'event_id' => 1,
                                'event_title' => '7th India International DRI & Steel Summit 2026',
                                'short_description' => 'Shaping the future of Indian steel industry',
                                'event_image' => 'https://example.com/images/summit_2026.png',
                                'organizer_name' => 'BigMint',
                                'organizer_logo' => 'https://example.com/logos/bigmint.png',
                                'event_date' => '9 - 11 April 2026',
                                'end_date' => '2026-04-11',
                                'event_location' => 'Hotel Le Meridien, Delhi, India',
                                'going_count' => '+2000 Going',
                                'detail_link' => 'https://example.com/events/registration/1',
                            ],
                            [
                                'event_id' => 2,
                                'event_title' => 'Global Non-Ferrous Markets Summit 2026',
                                'short_description' => 'Navigating the future of metals & minerals',
                                'event_image' => 'https://example.com/images/market_2026.png',
                                'organizer_name' => 'BigMint',
                                'organizer_logo' => 'https://example.com/logos/bigmint.png',
                                'event_date' => '15 - 16 June 2026',
                                'end_date' => '2026-06-16',
                                'event_location' => 'Hotel Taj, Mumbai, India',
                                'going_count' => '+3000 Going',
                                'detail_link' => 'https://example.com/events/registration/2',
                            ],
                            [
                                'event_id' => 3,
                                'event_title' => 'BigMint India Ferrous Week 2026',
                                'short_description' => "India's largest ferrous industry gathering",
                                'event_image' => 'https://example.com/images/ferrous_week_2025.png',
                                'organizer_name' => 'BigMint',
                                'organizer_logo' => 'https://example.com/logos/bigmint.png',
                                'event_date' => '19 - 21 August 2025',
                                'end_date' => '2025-08-21',
                                'event_location' => 'Hotel Lalit, Raipur',
                                'going_count' => '+3500 Attended',
                                'detail_link' => 'https://example.com/events/past/registration/3',
                            ],
                        ],
                    ],
                ],
                'videos_podcasts' => [
                    'view_all_link' => 'https://example.com/media/all',
                    'items' => [
                        [
                            'media_id' => 1,
                            'title' => 'Steel Price Forecast: Expert Panel Discussion',
                            'thumbnail_url' => 'https://example.com/thumb1.png',
                            'embed_link' => 'https://www.youtube.com/embed/dQw4w9WgXcQ',
                            'media_type_label' => 'LIVE',
                            'organizer' => 'Bigmint',
                            'views' => '1.2k',
                            'read_time' => '5 min read',
                        ],
                        [
                            'media_id' => 2,
                            'title' => 'Market pulse Weekly Ep. 42',
                            'thumbnail_url' => 'https://example.com/thumb2.png',
                            'embed_link' => 'https://www.youtube.com/embed/3tmd-ClpJxA',
                            'media_type_label' => 'PODCAST',
                            'organizer' => 'Bigmint',
                            'views' => '1.5k',
                            'read_time' => '1 min read',
                        ],
                    ],
                ],
                'editors_pick' => [
                    'view_all_link' => 'https://example.com/editors-pick/all',
                    'items' => [
                        [
                            'news_id' => 401,
                            'news_type' => 'Intel',
                            'commodity' => 'Iron Ore',
                            'title' => "India steel demand to grow 8-10% in FY27 on infrastructure push",
                            'published_at' => '29 Jan 12:00 IST',
                            'read_time' => '6 min read',
                            'thumbnail_image' => 'https://example.com/icons/steel_blue.png',
                            'detail_link' => 'https://example.com/news/global-iron-ore-trends',
                        ],
                        [
                            'news_id' => 402,
                            'news_type' => 'Insight',
                            'commodity' => 'Coal & Energy',
                            'title' => "Green hydrogen push could reshape India's steel making...",
                            'published_at' => '28 Jan 16:45 IST',
                            'read_time' => '5 min read',
                            'thumbnail_image' => 'https://example.com/icons/up_arrow_green.png',
                            'detail_link' => 'https://example.com/news/global-iron-ore-trends',
                        ],
                    ],
                ],
                'infographics' => [
                    'view_all_link' => 'https://example.com/infographics/all',
                    'items' => [
                        [
                            'infographic_id' => 901,
                            'title' => 'India Steel Production 2025',
                            'source' => 'BigMint',
                            'date' => '8 Mar 2026',
                            'thumbnail_image' => 'https://example.com/images/infog_steel.png',
                            'detail_link' => 'https://example.com/share/infog/901',
                            'is_bookmarked' => false,
                        ],
                        [
                            'infographic_id' => 902,
                            'title' => 'Coal Supply Analysis',
                            'source' => 'BigMint',
                            'date' => '1 Mar 2026',
                            'thumbnail_image' => 'https://example.com/images/infog_steel.png',
                            'share_link' => 'https://example.com/share/infog/901',
                            'is_bookmarked' => false,
                        ],
                    ],
                ],
                'tenders' => [
                    'view_all_link' => 'https://example.com/tenders/all',
                    'items' => [
                        [
                            'tender_id' => 1001,
                            'title' => 'SAIL Bhilai TMT Bars',
                            'tender_type' => 'SELL',
                            'closes_in' => '2 days to go',
                            'quantity' => '5,000 MT',
                            'location' => 'Bhilai, Chhattisgarh',
                            'auction_type' => 'E-Auction',
                            'base_price' => '₹38,500/MT',
                            'time_elapsed_percentage' => 78,
                            'closing_date' => "22th March'26",
                            'redirect_link' => 'https://example.com/tenders/1001',
                        ],
                        [
                            'tender_id' => 1002,
                            'title' => 'NMDC Iron Ore',
                            'tender_type' => 'SELL',
                            'closes_in' => '4 days to go',
                            'quantity' => '10,000 MT',
                            'location' => 'Dantewada, Chhattisgarh',
                            'auction_type' => 'E-Auction',
                            'base_price' => '₹4,200/MT',
                            'time_elapsed_percentage' => 65,
                            'closing_date' => "24th March'26",
                            'redirect_link' => 'https://example.com/tenders/1002',
                        ],
                    ],
                ],
                'relationship_manager' => [
                    'section_title' => 'YOUR RELATIONSHIP MANAGER',
                    'manager_name' => 'Pankaj Thakur',
                    'manager_email' => 'pankaj@bigmint.co',
                    'designation' => 'Manager',
                    'actions' => [
                        'call_link' => 'tel:+91XXXXXXXXXX',
                        'email_link' => 'mailto:pankaj@bigmint.co',
                    ],
                ],
            ],
        ], 200);
    }

    public function homeMarket(Request $request, $marketId)
    {
        $validator = Validator::make(['marketId' => $marketId], [
            'marketId' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Ferrous dashboard layout fetched successfully',
            'data' => [
                'market' => 'Ferrous',
                'market_id' => (string) $marketId,
                'navigation_bar' => [
                    'back_button' => true,
                    'title' => 'Ferrous',
                    'actions' => ['share', 'notifications'],
                ],
                'main_categories' => [
                    [
                        'label' => 'Prices',
                        'image_url' => 'https://api.example.com/assets/images/prices_bg.png',
                        'icon_url' => 'https://api.example.com/assets/icons/prices.svg',
                        'url' => 'https://app.example.com/ferrous/prices',
                    ],
                    [
                        'label' => 'News',
                        'image_url' => 'https://api.example.com/assets/images/news_bg.png',
                        'icon_url' => 'https://api.example.com/assets/icons/news.svg',
                        'url' => 'https://app.example.com/ferrous/news',
                    ],
                    [
                        'label' => 'Tenders',
                        'image_url' => 'https://api.example.com/assets/images/tenders_bg.png',
                        'icon_url' => 'https://api.example.com/assets/icons/tenders.svg',
                        'url' => 'https://app.example.com/ferrous/tenders',
                    ],
                    [
                        'label' => 'Reports',
                        'image_url' => 'https://api.example.com/assets/images/reports_bg.png',
                        'icon_url' => 'https://api.example.com/assets/icons/reports.svg',
                        'url' => 'https://app.example.com/ferrous/reports',
                    ],
                    [
                        'label' => 'Statistics',
                        'image_url' => 'https://api.example.com/assets/images/stats_bg.png',
                        'icon_url' => 'https://api.example.com/assets/icons/statistics.svg',
                        'url' => 'https://app.example.com/ferrous/statistics',
                    ],
                    [
                        'label' => 'Events',
                        'image_url' => 'https://api.example.com/assets/images/events_bg.png',
                        'icon_url' => 'https://api.example.com/assets/icons/events.svg',
                        'url' => 'https://app.example.com/ferrous/events',
                    ],
                ],
                'links' => [
                    [
                        'text' => 'See our Methodology',
                        'action_type' => 'external_link',
                        'url' => 'https://app.example.com/methodology',
                    ],
                ],
                'commodity_selection' => [
                    'title' => 'Choose Your Commodity',
                    'items' => [
                        [
                            'name' => 'Iron Ore',
                            'background_color' => '#7B2E15',
                            'image_url' => 'https://api.example.com/assets/images/iron_ore.png',
                            'icon_url' => 'https://api.example.com/assets/icons/iron_ore.svg',
                            'url' => 'https://app.example.com/ferrous/iron-ore',
                        ],
                        [
                            'name' => 'Coal',
                            'background_color' => '#1A1614',
                            'image_url' => 'https://api.example.com/assets/images/coal.png',
                            'icon_url' => 'https://api.example.com/assets/icons/coal.svg',
                            'url' => 'https://app.example.com/ferrous/coal',
                        ],
                        [
                            'name' => 'Scrap & Met',
                            'background_color' => '#36404F',
                            'image_url' => 'https://api.example.com/assets/images/scrap_met.png',
                            'icon_url' => 'https://api.example.com/assets/icons/scrap.svg',
                            'url' => 'https://app.example.com/ferrous/scrap-met',
                        ],
                    ],
                ],
                'regional_trends' => [
                    'title' => 'Analyze Regional Trends',
                    'regions' => [
                        [
                            'label' => 'India',
                            'image_url' => 'https://api.example.com/assets/images/bg_india.png',
                            'icon_url' => 'https://api.example.com/assets/icons/flag_india.svg',
                            'url' => 'https://app.example.com/trends/india',
                        ],
                        [
                            'label' => 'China',
                            'background_color' => '#EF4B4B',
                            'image_url' => 'https://api.example.com/assets/images/bg_china.png',
                            'icon_url' => 'https://api.example.com/assets/icons/flag_china.svg',
                            'url' => 'https://app.example.com/trends/china',
                        ],
                        [
                            'label' => 'Australia',
                            'background_color' => '#4A86F7',
                            'image_url' => 'https://api.example.com/assets/images/bg_australia.png',
                            'icon_url' => 'https://api.example.com/assets/icons/flag_australia.svg',
                            'url' => 'https://app.example.com/trends/australia',
                        ],
                    ],
                ],
                'flash_news' => [
                    'view_all_link' => 'https://example.com/news/all',
                    'items' => [
                        [
                            'news_id' => 101,
                            'news_type' => 'Intel',
                            'title' => "Global iron ore exports show divergent trends in CY'25; India shipment falls 30% YoY",
                            'published_date' => '29 Jan 2026, 15:51 IST',
                            'read_time' => '3 min read',
                            'thumbnail_image' => 'https://dummyimage.com/400x250/000/fff&text=News+Image',
                            'detail_link' => 'https://example.com/news/global-iron-ore-trends',
                        ],
                        [
                            'news_id' => 102,
                            'news_type' => 'Insight',
                            'title' => 'Coal prices stabilize as winter demand cools down across Asia',
                            'published_date' => '30 Jan 2026, 10:20 IST',
                            'read_time' => '5 min read',
                            'thumbnail_image' => 'https://dummyimage.com/400x250/000/fff&text=News+Image+2',
                            'detail_link' => 'https://example.com/news/coal-price-update',
                        ],
                        [
                            'news_id' => 103,
                            'news_type' => 'Insight',
                            'title' => 'Metcoke prices stabilize as winter demand cools down across Africa',
                            'published_date' => '31 Jan 2026, 10:20 IST',
                            'read_time' => '5 min read',
                            'thumbnail_image' => 'https://dummyimage.com/400x250/000/fff&text=News+Image+2',
                            'detail_link' => 'https://example.com/news/coal-price-edit',
                        ],
                    ],
                ],
                'prices' => [
                    'view_all_link' => 'https://example.com/prices/all',
                    'items' => [
                        [
                            'assesment_id' => 1,
                            'commodity' => 'Iron Ore',
                            'sub_commodity' => 'fines/lumps',
                            'price' => '7,250',
                            'currency' => 'INR',
                            'trade_type' => 'domestic',
                            'change' => '+150',
                            'change_percent' => '2.1%',
                            'arrow' => 'up',
                            'title' => 'Iron Ore Lumps, Odisha Index',
                            'size_grade' => '5-18mm, Fe 60%',
                            'published_date' => '2026-02-01',
                            'frequency' => 'Daily',
                        ],
                        [
                            'assesment_id' => 2,
                            'commodity' => 'coal',
                            'sub_commodity' => 'Coking Coal',
                            'price' => '98.50',
                            'currency' => 'USD',
                            'trade_type' => 'global',
                            'change' => '-2.30',
                            'change_percent' => '2.3%',
                            'arrow' => 'down',
                            'title' => 'Iron Ore Fines, CFR China',
                            'size_grade' => '62/63% Fe (India Origin)',
                            'published_date' => '2026-02-01',
                            'frequency' => 'Weekly',
                        ],
                    ],
                ],
                'reports' => [
                    'view_all_link' => 'https://example.com/reports/all',
                    'items' => [
                        [
                            'report_id' => 501,
                            'title' => 'India Iron Ore Market Outlook 2026',
                            'detail_link' => 'https://example.com/report/iron-ore-2026',
                        ],
                        [
                            'report_id' => 502,
                            'title' => 'Steel Industry Annual Review',
                            'detail_link' => 'https://example.com/report/steel-annual',
                        ],
                        [
                            'report_id' => 503,
                            'title' => 'Coal Market Monthly Jan 2026',
                            'detail_link' => 'https://example.com/report/coal-monthly',
                        ],
                    ],
                ],
                'analyst_corner' => [
                    'view_all_link' => 'https://example.com/analyst/all',
                    'items' => [
                        [
                            'news_id' => 1,
                            'news_type' => 'Insight',
                            'title' => 'Iron ore prices likely to stay range-bound in Q1 FY27 amid weak...',
                            'published_date' => '29 Jan 16:00 IST',
                            'read_time' => '4 min read',
                            'thumbnail_image' => 'https://example.com/images/analyst1.png',
                            'detail_link' => 'https://example.com/analyst/iron-ore-prices',
                        ],
                        [
                            'news_id' => 2,
                            'news_type' => 'Intel',
                            'title' => 'Steel exports from India may rise 15% in FY26 on global demand...',
                            'published_date' => '28 Jan 10:30 IST',
                            'read_time' => '5 min read',
                            'thumbnail_image' => 'https://example.com/images/analyst2.png',
                            'detail_link' => 'https://example.com/analyst/steel-exports',
                        ],
                        [
                            'news_id' => 3,
                            'news_type' => 'Intel',
                            'title' => 'Copper supply deficit to widen in 2026; prices may test $10,500/t',
                            'published_date' => '27 Jan 14:15 IST',
                            'read_time' => '3 min read',
                            'thumbnail_image' => 'https://example.com/images/analyst3.png',
                            'detail_link' => 'https://example.com/analyst/copper-supply',
                        ],
                        [
                            'news_id' => 4,
                            'news_type' => 'Insight',
                            'title' => 'Domestic coal production on track to hit 1 BT target by FY27',
                            'published_date' => '26 Jan 09:45 IST',
                            'read_time' => '4 min read',
                            'thumbnail_image' => 'https://example.com/images/analyst4.png',
                            'detail_link' => 'https://example.com/analyst/coal-production',
                        ],
                    ],
                ],
                'featured_events' => [
                    'view_all_link' => 'https://example.com/events/all',
                    'event' => [
                        'items' => [
                            [
                                'event_id' => 1,
                                'event_title' => '7th India International DRI & Steel Summit 2026',
                                'short_description' => 'Shaping the future of Indian steel industry',
                                'event_image' => 'https://example.com/images/summit_2026.png',
                                'organizer_name' => 'BigMint',
                                'organizer_logo' => 'https://example.com/logos/bigmint.png',
                                'event_date' => '9 - 11 April 2026',
                                'end_date' => '2026-04-11',
                                'event_location' => 'Hotel Le Meridien, Delhi, India',
                                'going_count' => '+2000 Going',
                                'detail_link' => 'https://example.com/events/registration/1',
                            ],
                            [
                                'event_id' => 2,
                                'event_title' => 'Global Non-Ferrous Markets Summit 2026',
                                'short_description' => 'Navigating the future of metals & minerals',
                                'event_image' => 'https://example.com/images/market_2026.png',
                                'organizer_name' => 'BigMint',
                                'organizer_logo' => 'https://example.com/logos/bigmint.png',
                                'event_date' => '15 - 16 June 2026',
                                'end_date' => '2026-06-16',
                                'event_location' => 'Hotel Taj, Mumbai, India',
                                'going_count' => '+3000 Going',
                                'detail_link' => 'https://example.com/events/registration/2',
                            ],
                            [
                                'event_id' => 3,
                                'event_title' => 'BigMint India Ferrous Week 2026',
                                'short_description' => "India's largest ferrous industry gathering",
                                'event_image' => 'https://example.com/images/ferrous_week_2025.png',
                                'organizer_name' => 'BigMint',
                                'organizer_logo' => 'https://example.com/logos/bigmint.png',
                                'event_date' => '19 - 21 August 2025',
                                'end_date' => '2025-08-21',
                                'event_location' => 'Hotel Lalit, Raipur',
                                'going_count' => '+3500 Attended',
                                'detail_link' => 'https://example.com/events/past/registration/3',
                            ],
                        ],
                    ],
                ],
                'videos_podcasts' => [
                    'view_all_link' => 'https://example.com/media/all',
                    'items' => [
                        [
                            'media_id' => 1,
                            'title' => 'Steel Price Forecast: Expert Panel Discussion',
                            'thumbnail_url' => 'https://example.com/thumb1.png',
                            'embed_link' => 'https://www.youtube.com/embed/dQw4w9WgXcQ',
                            'media_type_label' => 'LIVE',
                            'organizer' => 'Bigmint',
                            'views' => '1.2k',
                            'read_time' => '5 min read',
                        ],
                        [
                            'media_id' => 2,
                            'title' => 'Market pulse Weekly Ep. 42',
                            'thumbnail_url' => 'https://example.com/thumb2.png',
                            'embed_link' => 'https://www.youtube.com/embed/3tmd-ClpJxA',
                            'media_type_label' => 'PODCAST',
                            'organizer' => 'Bigmint',
                            'views' => '1.5k',
                            'read_time' => '1 min read',
                        ],
                    ],
                ],
                'editors_pick' => [
                    'view_all_link' => 'https://example.com/editors-pick/all',
                    'items' => [
                        [
                            'news_id' => 401,
                            'news_type' => 'Intel',
                            'commodity' => 'Iron Ore',
                            'title' => 'India steel demand to grow 8-10% in FY27 on infrastructure push',
                            'published_at' => '29 Jan 12:00 IST',
                            'read_time' => '6 min read',
                            'thumbnail_image' => 'https://example.com/icons/steel_blue.png',
                            'detail_link' => 'https://example.com/news/global-iron-ore-trends',
                        ],
                        [
                            'news_id' => 402,
                            'news_type' => 'Insight',
                            'commodity' => 'Coal & Energy',
                            'title' => "Green hydrogen push could reshape India's steel making...",
                            'published_at' => '28 Jan 16:45 IST',
                            'read_time' => '5 min read',
                            'thumbnail_image' => 'https://example.com/icons/up_arrow_green.png',
                            'detail_link' => 'https://example.com/news/global-iron-ore-trends',
                        ],
                    ],
                ],
                'infographics' => [
                    'view_all_link' => 'https://example.com/infographics/all',
                    'items' => [
                        [
                            'infographic_id' => 901,
                            'title' => 'India Steel Production 2025',
                            'source' => 'BigMint',
                            'date' => '8 Mar 2026',
                            'thumbnail_image' => 'https://example.com/images/infog_steel.png',
                            'detail_link' => 'https://example.com/share/infog/901',
                            'is_bookmarked' => false,
                        ],
                        [
                            'infographic_id' => 902,
                            'title' => 'Coal Supply Analysis',
                            'source' => 'BigMint',
                            'date' => '1 Mar 2026',
                            'thumbnail_image' => 'https://example.com/images/infog_steel.png',
                            'share_link' => 'https://example.com/share/infog/901',
                            'is_bookmarked' => false,
                        ],
                    ],
                ],
                'tenders' => [
                    'view_all_link' => 'https://example.com/tenders/all',
                    'items' => [
                        [
                            'tender_id' => 1001,
                            'title' => 'SAIL Bhilai TMT Bars',
                            'type_type' => 'SELL',
                            'closes_in' => '2d 6h',
                            'quantity' => '5,000 MT',
                            'location' => 'Bhilai, Chhattisgarh',
                            'auction_type' => 'E-Auction',
                            'base_price' => '₹38,500/MT',
                            'time_elapsed_percentage' => 78,
                            'closing_date' => '18 Mar',
                            'redirect_link' => 'https://example.com/tenders/1001',
                        ],
                        [
                            'tender_id' => 1002,
                            'title' => 'NMDC Iron Ore',
                            'type_type' => 'SELL',
                            'closes_in' => '1d 4h',
                            'quantity' => '10,000 MT',
                            'location' => 'Dantewada, Chhattisgarh',
                            'auction_type' => 'E-Auction',
                            'base_price' => '₹4,200/MT',
                            'time_elapsed_percentage' => 65,
                            'closing_date' => '17 Mar',
                            'redirect_link' => 'https://example.com/tenders/1002',
                        ],
                    ],
                ],
                'market_pulse' => [
                    [
                        'market' => 'Ferrous',
                        'prices' => [
                            [
                                'sub_commodity' => 'Iron Ore Lumps, Odisha',
                                'size_grade' => '2.5mm, IS 2062 E250',
                                'trade_type' => 'Domestic',
                                'price' => '₹7,250',
                                'change' => '+₹150',
                                'change_percent' => '2.1%',
                                'arrow' => 'up',
                            ],
                            [
                                'sub_commodity' => 'Iron Ore Fines, China',
                                'size_grade' => '2.5mm, IS 2062 E250',
                                'trade_type' => 'Domestic',
                                'price' => '$98.50',
                                'change' => '-$2.30',
                                'change_percent' => '2.3%',
                                'arrow' => 'down',
                            ],
                            [
                                'sub_commodity' => 'Iron Ore Pellet, Exw',
                                'size_grade' => '2.5mm, IS 2062 E250',
                                'trade_type' => 'Domestic',
                                'price' => '₹9,100',
                                'change' => '+₹135',
                                'change_percent' => '1.5%',
                                'arrow' => 'up',
                            ],
                            [
                                'sub_commodity' => 'Iron Ore Fines, Barbil',
                                'size_grade' => '2.5mm, IS 2062 E250',
                                'trade_type' => 'Domestic',
                                'price' => '₹4,800',
                                'change' => '+₹30',
                                'change_percent' => '0.6%',
                                'arrow' => 'up',
                            ],
                        ],
                        'news' => [
                            [
                                'title' => 'Iron ore auction volumes rise 18% in Odisha in Jan 2026',
                                'date_time' => '29 Jan 15:30 IST',
                            ],
                            [
                                'title' => 'NMDC holds prices steady for February amid demand uncertainty',
                                'date_time' => '29 Jan 12:00 IST',
                            ],
                            [
                                'title' => 'China iron ore port stocks fall to 4-month low of 120 MT',
                                'date_time' => '28 Jan 18:15 IST',
                            ],
                            [
                                'title' => 'India iron ore exports decline 30% YoY in Apr-Dec FY26',
                                'date_time' => '28 Jan 11:00 IST',
                            ],
                        ],
                    ],
                    [
                        'market' => 'Non Ferrous',
                        'prices' => [
                            [
                                'sub_commodity' => 'Copper Cathode',
                                'size_grade' => '2.5mm, IS 2062 E250',
                                'trade_type' => 'Domestic',
                                'price' => '$8,420',
                                'change' => '-$45',
                                'percentage_change' => '0.5%',
                                'arrow' => 'down',
                            ],
                            [
                                'sub_commodity' => 'Aluminum Ingot',
                                'size_grade' => '2.5mm, IS 2062 E250',
                                'trade_type' => 'Domestic',
                                'price' => '₹212',
                                'change' => '+₹3.5',
                                'percentage_change' => '1.7%',
                                'arrow' => 'up',
                            ],
                        ],
                        'news' => [
                            [
                                'title' => 'LME copper stocks surge as Asian demand softens',
                                'date_time' => '29 Jan 10:00 IST',
                            ],
                            [
                                'title' => 'New aluminum smelting capacity comes online in Middle East',
                                'date_time' => '28 Jan 14:20 IST',
                            ],
                        ],
                    ],
                    [
                        'market' => 'Coal & Energy',
                        'prices' => [
                            [
                                'sub_commodity' => 'Thermal Coal',
                                'size_grade' => '2.5mm, IS 2062 E250',
                                'trade_type' => 'Domestic',
                                'price' => '$92.10',
                                'change' => '+$1.20',
                                'percentage_change' => '1.3%',
                                'arrow' => 'up',
                            ],
                            [
                                'sub_commodity' => 'Brent Crude Oil',
                                'size_grade' => '2.5mm, IS 2062 E250',
                                'trade_type' => 'Domestic',
                                'price' => '$81.45',
                                'change' => '-$0.90',
                                'percentage_change' => '1.1%',
                                'arrow' => 'down',
                            ],
                        ],
                        'news' => [
                            [
                                'title' => 'Coal India reports 12% growth in production for Q3',
                                'date_time' => '29 Jan 09:15 IST',
                            ],
                            [
                                'title' => 'OPEC+ signals potential extension of supply cuts through March',
                                'date_time' => '27 Jan 16:45 IST',
                            ],
                        ],
                    ],
                    [
                        'market' => 'Agriculture',
                        'prices' => [
                            [
                                'sub_commodity' => 'Wheat',
                                'size_grade' => '2.5mm, IS 2062 E250',
                                'trade_type' => 'Domestic',
                                'price' => '₹2,650',
                                'change' => '+₹40',
                                'percentage_change' => '1.5%',
                                'arrow' => 'up',
                            ],
                            [
                                'sub_commodity' => 'Soybean',
                                'size_grade' => '2.5mm, IS 2062 E250',
                                'trade_type' => 'Domestic',
                                'price' => '₹4,120',
                                'change' => '-₹25',
                                'percentage_change' => '0.6%',
                                'arrow' => 'down',
                            ],
                        ],
                        'news' => [
                            [
                                'title' => 'Wheat sowing area hits record high in Northern India',
                                'date_time' => '29 Jan 13:00 IST',
                            ],
                            [
                                'title' => 'Global palm oil prices stabilize amid improved Malaysian output',
                                'date_time' => '28 Jan 11:30 IST',
                            ],
                        ],
                    ],
                ],
            ],
        ], 200);
    }

    public function homeMarketPulse(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'market' => 'sometimes|string|max:100',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'market-pulse data retrieved successfully',
            'market_pulse' => [
                [
                    'market' => 'Ferrous',
                    'prices' => [
                        [
                            'sub_commodity' => 'Iron Ore Lumps, Odisha',
                            'size_grade' => '2.5mm, IS 2062 E250',
                            'trade_type' => 'Domestic',
                            'price' => '₹7,250',
                            'change' => '+₹150',
                            'change_percent' => '2.1%',
                            'arrow' => 'up',
                        ],
                        [
                            'sub_commodity' => 'Iron Ore Fines, China',
                            'size_grade' => '2.5mm, IS 2062 E250',
                            'trade_type' => 'Domestic',
                            'price' => '$98.50',
                            'change' => '-$2.30',
                            'change_percent' => '2.3%',
                            'arrow' => 'down',
                        ],
                        [
                            'sub_commodity' => 'Iron Ore Pellet, Exw',
                            'size_grade' => '2.5mm, IS 2062 E250',
                            'trade_type' => 'Domestic',
                            'price' => '₹9,100',
                            'change' => '+₹135',
                            'change_percent' => '1.5%',
                            'arrow' => 'up',
                        ],
                        [
                            'sub_commodity' => 'Iron Ore Fines, Barbil',
                            'size_grade' => '2.5mm, IS 2062 E250',
                            'trade_type' => 'Domestic',
                            'price' => '₹4,800',
                            'change' => '+₹30',
                            'change_percent' => '0.6%',
                            'arrow' => 'up',
                        ],
                    ],
                    'news' => [
                        [
                            'title' => 'Iron ore auction volumes rise 18% in Odisha in Jan 2026',
                            'date_time' => '29 Jan 15:30 IST',
                        ],
                        [
                            'title' => 'NMDC holds prices steady for February amid demand uncertainty',
                            'date_time' => '29 Jan 12:00 IST',
                        ],
                        [
                            'title' => 'China iron ore port stocks fall to 4-month low of 120 MT',
                            'date_time' => '28 Jan 18:15 IST',
                        ],
                        [
                            'title' => 'India iron ore exports decline 30% YoY in Apr-Dec FY26',
                            'date_time' => '28 Jan 11:00 IST',
                        ],
                    ],
                ],
                [
                    'market' => 'Non Ferrous',
                    'prices' => [
                        [
                            'sub_commodity' => 'Copper Cathode',
                            'size_grade' => '2.5mm, IS 2062 E250',
                            'trade_type' => 'Domestic',
                            'price' => '$8,420',
                            'change' => '-$45',
                            'percentage_change' => '0.5%',
                            'arrow' => 'down',
                        ],
                        [
                            'sub_commodity' => 'Aluminum Ingot',
                            'size_grade' => '2.5mm, IS 2062 E250',
                            'trade_type' => 'Domestic',
                            'price' => '₹212',
                            'change' => '+₹3.5',
                            'percentage_change' => '1.7%',
                            'arrow' => 'up',
                        ],
                    ],
                    'news' => [
                        [
                            'title' => 'LME copper stocks surge as Asian demand softens',
                            'date_time' => '29 Jan 10:00 IST',
                        ],
                        [
                            'title' => 'New aluminum smelting capacity comes online in Middle East',
                            'date_time' => '28 Jan 14:20 IST',
                        ],
                    ],
                ],
                [
                    'market' => 'Coal & Energy',
                    'prices' => [
                        [
                            'sub_commodity' => 'Thermal Coal',
                            'size_grade' => '2.5mm, IS 2062 E250',
                            'trade_type' => 'Domestic',
                            'price' => '$92.10',
                            'change' => '+$1.20',
                            'percentage_change' => '1.3%',
                            'arrow' => 'up',
                        ],
                        [
                            'sub_commodity' => 'Brent Crude Oil',
                            'size_grade' => '2.5mm, IS 2062 E250',
                            'trade_type' => 'Domestic',
                            'price' => '$81.45',
                            'change' => '-$0.90',
                            'percentage_change' => '1.1%',
                            'arrow' => 'down',
                        ],
                    ],
                    'news' => [
                        [
                            'title' => 'Coal India reports 12% growth in production for Q3',
                            'date_time' => '29 Jan 09:15 IST',
                        ],
                        [
                            'title' => 'OPEC+ signals potential extension of supply cuts through March',
                            'date_time' => '27 Jan 16:45 IST',
                        ],
                    ],
                ],
                [
                    'market' => 'Agriculture',
                    'prices' => [
                        [
                            'sub_commodity' => 'Wheat',
                            'size_grade' => '2.5mm, IS 2062 E250',
                            'trade_type' => 'Domestic',
                            'price' => '₹2,650',
                            'change' => '+₹40',
                            'percentage_change' => '1.5%',
                            'arrow' => 'up',
                        ],
                        [
                            'sub_commodity' => 'Soybean',
                            'size_grade' => '2.5mm, IS 2062 E250',
                            'trade_type' => 'Domestic',
                            'price' => '₹4,120',
                            'change' => '-₹25',
                            'percentage_change' => '0.6%',
                            'arrow' => 'down',
                        ],
                    ],
                    'news' => [
                        [
                            'title' => 'Wheat sowing area hits record high in Northern India',
                            'date_time' => '29 Jan 13:00 IST',
                        ],
                        [
                            'title' => 'Global palm oil prices stabilize amid improved Malaysian output',
                            'date_time' => '28 Jan 11:30 IST',
                        ],
                    ],
                ],
            ],
        ], 200);
    }

    public function portfolioDashboard(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'limit' => 'sometimes|integer|min:1|max:50',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Portfolio dashboard data fetched successfully',
            'data' => [
                'flash_news' => [
                    [
                        'news_id' => 101,
                        'news_type' => 'Intel',
                        'title' => "Global iron ore exports show divergent trends in CY'25; India shipment falls 30% YoY",
                        'published_date' => '29 Jan 2026, 15:51 IST',
                        'read_time' => '3 min read',
                        'thumbnail_image' => 'https://dummyimage.com/400x250/000/fff&text=News+Image',
                        'detail_link' => 'https://example.com/news/global-iron-ore-trends',
                    ],
                    [
                        'news_id' => 102,
                        'news_type' => 'Insight',
                        'title' => 'Coal prices stabilize as winter demand cools down across Asia',
                        'published_date' => '30 Jan 2026, 10:20 IST',
                        'read_time' => '5 min read',
                        'thumbnail_image' => 'https://dummyimage.com/400x250/000/fff&text=News+Image+2',
                        'detail_link' => 'https://example.com/news/coal-price-update',
                    ],
                ],
                'watchlists' => [
                    [
                        'id' => 1,
                        'name' => 'Agriculture',
                        'items' => [
                            [
                                'commodity' => 'Soybean',
                                'sub_commodity' => 'FAQ Grade',
                                'sub_sub_commodity' => 'FAQ Grade',
                                'assessment_id' => '1068',
                                'title' => 'Soybean Indore Market',
                                'size_grade' => '2.5mm,IS 2062 E250',
                                'published_date' => '-',
                                'frequency' => 'D',
                                'currency' => 'INR',
                                'trade_type' => 'domestic',
                                'price' => '₹4,250',
                                'change' => '<span style="color: green;"> +50</span>',
                                'change_percent' => 1.2,
                                'previous_price' => '4200',
                                'arrow' => 'up',
                                '1W' => '₹4,100',
                                '1M' => '₹4,000',
                                '3M' => '₹4,300',
                            ],
                            [
                                'commodity' => 'Mustard Seed',
                                'sub_commodity' => 'Bold Grade',
                                'sub_sub_commodity' => 'Bold Grade',
                                'assessment_id' => '1069',
                                'title' => 'Mustard Jaipur Market',
                                'size_grade' => '2.5mm,IS 2062 E250',
                                'published_date' => '-',
                                'frequency' => 'D',
                                'currency' => 'INR',
                                'trade_type' => 'domestic',
                                'price' => '₹5,800',
                                'change' => '<span style="color: red;"> -75</span>',
                                'change_percent' => -1.3,
                                'previous_price' => '5875',
                                'arrow' => 'down',
                                '1W' => '₹5,900',
                                '1M' => '₹6,000',
                                '3M' => '₹5,700',
                            ],
                        ],
                    ],
                    [
                        'id' => 2,
                        'name' => 'Metals',
                        'items' => [
                            [
                                'commodity' => 'Iron Ore',
                                'sub_commodity' => 'Fines/Lumps',
                                'sub_sub_commodity' => 'Fines/Lumps',
                                'assessment_id' => '1068',
                                'title' => 'Iron Ore Fines, CNF Qingdao, China',
                                'size_grade' => '2.5mm,IS 2062 E250',
                                'published_date' => '-',
                                'frequency' => 'W',
                                'currency' => 'USD',
                                'trade_type' => 'domestic',
                                'price' => '$76.5',
                                'change' => '<span style="text-align: center; color: #000;"> 0</span>',
                                'change_percent' => 0,
                                'previous_price' => '76.5000',
                                'arrow' => 'up',
                                '1W' => '$75.75',
                                '1M' => '$70.5',
                                '3M' => '$77.5',
                            ],
                        ],
                    ],
                ],
                'analyst_corner' => [
                    [
                        'news_id' => 1,
                        'news_type' => 'Insight',
                        'title' => 'Iron ore prices likely to stay range-bound in Q1 FY27 amid weak...',
                        'published_date' => '29 Jan 16:00 IST',
                        'read_time' => '4 min read',
                        'thumbnail_image' => 'https://example.com/images/analyst1.png',
                        'detail_link' => 'https://example.com/analyst/iron-ore-prices',
                    ],
                    [
                        'news_id' => 2,
                        'news_type' => 'Intel',
                        'title' => 'Steel exports from India may rise 15% in FY26 on global demand...',
                        'published_date' => '28 Jan 10:30 IST',
                        'read_time' => '5 min read',
                        'thumbnail_image' => 'https://example.com/images/analyst2.png',
                        'detail_link' => 'https://example.com/analyst/steel-exports',
                    ],
                ],
                'tenders' => [
                    [
                        'tender_id' => 1001,
                        'title' => 'SAIL Bhilai TMT Bars',
                        'tender_type' => 'SELL',
                        'closes_in' => '2 days to go',
                        'quantity' => '5,000 MT',
                        'location' => 'Bhilai, Chhattisgarh',
                        'auction_type' => 'E-Auction',
                        'base_price' => '₹38,500/MT',
                        'time_elapsed_percentage' => 78,
                        'closing_date' => "22th March'26",
                        'redirect_link' => 'https://example.com/tenders/1001',
                    ],
                ],
                'reports' => [
                    [
                        'report_id' => 501,
                        'title' => 'India Iron Ore Market Outlook 2026',
                        'detail_link' => 'https://example.com/report/iron-ore-2026',
                    ],
                ],
            ],
        ], 200);
    }

    public function watchlistsStore(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'name' => 'required|string|max:255',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'watchlist created successfully',
            'data' => [
                'watchlist_id' => (int) (time() % 1000000),
                'name' => $request->input('name'),
                'created_at' => gmdate('c'),
            ],
        ], 201);
    }

    public function watchlistsIndex(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Watchlists fetched successfully',
            'data' => [
                [
                    'id' => 1,
                    'name' => 'My Watchlist',
                    'created_at' => '2026-03-18T10:00:00Z',
                    'items' => [
                        [
                            'assessment_id' => 6,
                            'commodity' => 'Iron Ore',
                            'sub_commodity' => 'Fines/Lumps',
                            'sub_sub_commodity' => 'Fines/Lumps',
                            'title' => 'Iron Ore Fines, CNF Qingdao, China',
                            'size_grade' => '2.5mm,IS 2062 E250',
                            'published_date' => '-',
                            'frequency' => 'W',
                            'currency' => 'USD',
                            'trade_type' => 'domestic',
                            'price' => '$76.5',
                            'change' => '<span style="text-align: center; color: #000;"> 0</span>',
                            'change_percent' => 0,
                            'previous_price' => '76.5000',
                            'arrow' => 'up',
                            '1W' => '$75.75',
                            '1M' => '$70.5',
                            '3M' => '$77.5',
                        ],
                        [
                            'assessment_id' => 8,
                            'commodity' => 'Steel',
                            'sub_commodity' => 'HRC',
                            'sub_sub_commodity' => 'HRC',
                            'title' => 'Hot Rolled Coil EXW India',
                            'size_grade' => '2.5mm,IS 2062 E250',
                            'published_date' => '-',
                            'frequency' => 'W',
                            'currency' => 'INR',
                            'trade_type' => 'domestic',
                            'price' => '₹52,000',
                            'change' => '<span style="text-align: center; color: red;"> -500</span>',
                            'change_percent' => -0.95,
                            'previous_price' => '52500',
                            'arrow' => 'down',
                            '1W' => '₹52,500',
                            '1M' => '₹53,200',
                            '3M' => '₹51,000',
                        ],
                    ],
                ],
                [
                    'id' => 2,
                    'name' => 'Metals',
                    'created_at' => '2026-03-17T09:00:00Z',
                    'items' => [],
                ],
            ],
        ], 200);
    }

    public function watchlistsUpdate(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->all(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            'name' => 'required|string|max:255',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Watchlist updated successfully',
            'data' => [
                'id' => (int) $id,
                'name' => $request->input('name'),
                'updated_at' => gmdate('c'),
            ],
        ], 200);
    }

    public function watchlistsDestroy(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Watchlist deleted successfully',
            'data' => null,
        ], 200);
    }

    public function watchlistsItemsStore(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->all(), ['watchlist_id' => $id]), [
            'watchlist_id' => 'required|integer|min:1',
            'assessment_id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Assessment  added to watchlist successfully',
            'data' => [
                'id' => 11,
                'watchlist_id' => (int) $id,
                'assessment_id' => (int) $request->input('assessment_id'),
                'created_at' => gmdate('c'),
            ],
        ], 201);
    }

    public function watchlistsItemsDestroy(Request $request, $id, $itemId)
    {
        $validator = Validator::make(['id' => $id, 'itemId' => $itemId], [
            'id' => 'required|integer|min:1',
            'itemId' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Item removed from watchlist successfully',
            'data' => null,
        ], 200);
    }

    public function portfolioCommoditySearch(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'search' => 'sometimes|string|max:255',
            'sterm' => 'sometimes|string|max:255',
            'sectionType' => 'sometimes|string|max:100',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        $sterm = (string) $request->query('search', $request->query('sterm', ''));
        if ($sterm === '') {
            return V2026LegacyBridge::jsonFromEnvelope(false, 'Provide search or sterm query parameter', new \stdClass(), 422);
        }

        $filters = V2026LegacyBridge::legacyFilters($request);
        $post = [
            'sterm' => $sterm,
            'sectionType' => (string) $request->query('sectionType', ''),
            'filters' => $filters,
        ];

        return $this->v2019Post(
            $request,
            \App\Http\Controllers\v2019\PricesController::class,
            'getPricesSearch',
            $post,
            ['client_paginate' => true]
        );
    }

    public function pricesDailyMovers(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Daily movers data fetched successfully',
            'auth_token' => '9876543210abcdef1234567890',
            'view_all_link' => 'https://api.example.com/v1/all-movers',
            'data' => [
                'top_gainers' => [
                    'list' => [
                        [
                            'assessment_id' => 101,
                            'commodity' => 'Iron Ore',
                            'sub_commodity' => 'fines/lumps',
                            'currency' => 'USD',
                            'trade_type' => 'global',
                            'size_grade' => '5-18mm, F...',
                            'price' => '₹7,250',
                            'title' => 'Iron Ore Lumps, Odisha Index',
                            'change' => '+₹150',
                            'change_percent' => '2.1%',
                            'arrow' => 'up',
                            'detail_link' => 'https://example.com/details/101',
                        ],
                        [
                            'assessment_id' => 102,
                            'commodity' => 'coal',
                            'sub_commodity' => 'Coking Coal',
                            'currency' => 'INR',
                            'trade_type' => 'domestic',
                            'size_grade' => 'CSN 9.0, ...',
                            'price' => '$220',
                            'title' => 'Met Coke, Raipur Index',
                            'change' => '+$3.96',
                            'change_percent' => '1.8%',
                            'arrow' => 'up',
                            'detail_link' => 'https://example.com/details/102',
                        ],
                        [
                            'assessment_id' => 103,
                            'commodity' => 'steel',
                            'sub_commodity' => 'Rebar',
                            'currency' => 'INR',
                            'trade_type' => 'domestic',
                            'size_grade' => '2mm, AS...',
                            'price' => '₹1,42,500',
                            'title' => 'billet, India Index',
                            'change' => '+₹1,500',
                            'change_percent' => '1.1%',
                            'arrow' => 'up',
                            'detail_link' => 'https://example.com/details/103',
                        ],
                    ],
                ],
                'top_losers' => [
                    'list' => [
                        [
                            'assessment_id' => 201,
                            'commodity' => 'grains',
                            'sub_commodity' => 'Soybean',
                            'currency' => 'INR',
                            'trade_type' => 'domestic',
                            'size_grade' => 'FAQ Grad...',
                            'price' => '₹4,250',
                            'title' => 'Rice, chhattisgarh india market',
                            'change' => '-₹160',
                            'change_percent' => '3.6%',
                            'arrow' => 'down',
                            'detail_link' => 'https://example.com/details/201',
                        ],
                        [
                            'assessment_id' => 202,
                            'commodity' => 'Scrap & metallics',
                            'sub_commodity' => 'Sponge Iron',
                            'currency' => 'USD',
                            'trade_type' => 'global',
                            'size_grade' => 'Fe 86%, ...',
                            'price' => '₹24,800',
                            'title' => 'melting scale, chhattisgarh india Index',
                            'change' => '-₹580',
                            'change_percent' => '2.3%',
                            'arrow' => 'down',
                            'detail_link' => 'https://example.com/details/202',
                        ],
                        [
                            'assessment_id' => 203,
                            'commodity' => 'Ferro Alloy',
                            'sub_commodity' => 'Ferro Chrome',
                            'currency' => 'INR',
                            'trade_type' => 'domestic',
                            'size_grade' => '60-65%...',
                            'price' => '₹82,000',
                            'title' => 'Ferro Chrome, chhattisgarh india Index',
                            'change' => '-₹8,200',
                            'change_percent' => '9.1%',
                            'arrow' => 'down',
                            'detail_link' => 'https://example.com/details/203',
                        ],
                    ],
                ],
            ],
        ], 200);
    }

    public function pricesRationale(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->query(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            'rational_id' => 'sometimes|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Rational details fetched successfully',
            'access_token' => '9876543210abcdef1234567890',
            'data' => [
                'rational_list' => [
                    [
                        'sentiment' => [
                            'bullish' => '50.00%',
                            'bearish' => '50.00%',
                        ],
                        'text' => 'The current bearishness in iron ore is driven mainly by a weakening demand outlook against a backdrop of ample supply.',
                    ],
                ],
            ],
        ], 200);
    }

    public function pricesNews(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'News updates fetched successfully',
            'access_token' => '9876543210abcdef1234567890',
            'data' => [
                'detail_page_id' => (int) $id,
                'list' => [
                    [
                        'news_id' => 1001,
                        'news_type' => 'Intel',
                        'commodity' => 'Iron Ore',
                        'sub_commodity' => 'Fines/Lumps',
                        'title' => 'Sensex Today | Nifty 50 | Stock Market Live Updates: Sensex rises 1200 Pts',
                        'thumbnail_image' => 'https://example.com/images/news1.png',
                        'published_date' => '29 Jan 15:51 IST',
                        'read_time' => '3 min read',
                        'detail_link' => 'https://example.com/news/1001',
                    ],
                    [
                        'news_id' => 1002,
                        'news_type' => 'Insights',
                        'commodity' => 'Iron Ore',
                        'sub_commodity' => 'Fines/Lumps',
                        'title' => 'India: Over 140,000 t of iron ore booked in Odisha auction',
                        'thumbnail_image' => 'https://example.com/images/news2.png',
                        'published_date' => '29 Jan 14:30 IST',
                        'read_time' => '2 min read',
                        'detail_link' => 'https://example.com/news/1002',
                    ],
                    [
                        'news_id' => 1003,
                        'news_type' => 'Intel',
                        'commodity' => 'Iron Ore',
                        'sub_commodity' => 'Fines/Lumps',
                        'title' => 'India DRI, billet, rebar update - 29 Jan',
                        'thumbnail_image' => 'https://example.com/images/news3.png',
                        'published_date' => '29 Jan 12:00 IST',
                        'read_time' => '2 min read',
                        'detail_link' => 'https://example.com/news/1003',
                    ],
                ],
            ],
        ], 200);
    }

    public function pricesStatusTags(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'The scheduled event or process has been delayed.',
            'data' => [
                'status' => 'DELAYED',
                'tooltip' => 'Price update delayed due to market holiday. Expected by 4:00 PM IST.',
            ],
        ], 200);
    }

    public function pricesIndia(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'market' => 'sometimes|string|max:100',
            'app_type' => 'sometimes|in:CM,SM',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        try {
            $ctrl = new \App\Http\Controllers\v2019\PricesController($request);
            $raw = $ctrl->indianPriceCategories($request);
        } catch (\Throwable $e) {
            Log::error($e->getMessage(), ['exception' => $e]);
            return V2026LegacyBridge::jsonFromEnvelope(false, 'Service temporarily unavailable', new \stdClass(), 500);
        }

        if ($raw === false || $raw === null || $raw === '') {
            return V2026LegacyBridge::jsonFromEnvelope(false, 'Unable to load India price categories', new \stdClass(), 502);
        }

        $norm = V2026LegacyBridge::normalizeEnvelope($raw);
        $data = $norm['data'];
        if (is_string($data)) {
            $decoded = json_decode($data, true);
            if (json_last_error() === JSON_ERROR_NONE) {
                $data = $decoded;
            }
        }

        $p = V2026LegacyBridge::paginationParams($request);
        if (is_array($data)) {
            $keys = array_keys($data);
            $isList = $keys === range(0, count($data) - 1);
            if ($isList) {
                list($items, $pagination) = V2026LegacyBridge::applyClientPagination($data, $p['page'], $p['per_page']);
                $data = ['items' => $items, 'pagination' => $pagination];
            }
        }

        return V2026LegacyBridge::jsonFromEnvelope($norm['ok'], $norm['message'] ?: 'India price categories', $data, 200);
    }

    public function pricesTable(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Tabular price published_dates fetched successfully',
            'data' => [
                'name' => 'TMT Bars - Mumbai',
                'unit' => '₹/ton',
                'items' => [
                    ['published_date' => '2026-01-29', 'price' => 49500, 'change' => 200, 'arrow' => 'up'],
                    ['published_date' => '2026-01-28', 'price' => 49300, 'change' => 150, 'arrow' => 'up'],
                    ['published_date' => '2026-01-27', 'price' => 49150, 'change' => -80, 'arrow' => 'down'],
                    ['published_date' => '2026-01-24', 'price' => 49230, 'change' => 310, 'arrow' => 'up'],
                    ['published_date' => '2026-01-23', 'price' => 48920, 'change' => -120, 'arrow' => 'down'],
                    ['published_date' => '2026-01-22', 'price' => 49040, 'change' => 180, 'arrow' => 'up'],
                ],
            ],
        ], 200);
    }

    public function pricesIndustryPulse(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'industry' => 'sometimes|string|max:100',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Industry assessments and market pricing retrieved successfully.',
            'data' => [
                'dashboard_summary' => [
                    'total_industries' => 8,
                    'total_assessments' => 457,
                    'total_news_articles' => '1.2K',
                ],
                'industries' => [
                    [
                        'commodity' => 'Steel',
                        'assessment_count' => 142,
                        'tag_market' => 'Ferrous',
                        'sub_categories' => [
                            [
                                'sub_commodity' => 'HR Coil',
                                'listings' => [
                                    [
                                        'country' => 'India',
                                        'size_grade' => '2.5mm,IS 2062 E250',
                                        'trade_type' => 'Domestic',
                                        'price' => 49500,
                                        'currency' => 'INR',
                                        'change_percent' => '+1.5%',
                                        'arrow' => 'up',
                                        'url' => '/price/1101011',
                                    ],
                                    [
                                        'country' => 'India',
                                        'size_grade' => '3.15mm,Commercial',
                                        'trade_type' => 'Domestic',
                                        'price' => 50200,
                                        'currency' => 'INR',
                                        'change_percent' => '+0.8%',
                                        'arrow' => 'up',
                                        'url' => '/price/1101011',
                                    ],
                                    [
                                        'country' => 'China',
                                        'size_grade' => 'N/A, SAE 1006',
                                        'trade_type' => 'FOB China',
                                        'price' => 540,
                                        'currency' => 'USD',
                                        'change_percent' => '-0.5%',
                                        'arrow' => 'down',
                                        'url' => '/price/1101011',
                                    ],
                                    [
                                        'country' => 'India',
                                        'size_grade' => 'N/A,SAE 1006',
                                        'trade_type' => 'Import',
                                        'price' => 555,
                                        'currency' => 'USD',
                                        'change_percent' => '+1.2%',
                                        'arrow' => 'up',
                                        'url' => '/price/1101011',
                                    ],
                                ],
                            ],
                            [
                                'sub_commodity' => 'CR Coil',
                                'listings' => [
                                    [
                                        'country' => 'India',
                                        'size_grade' => '1.0mm, CRCA',
                                        'trade_type' => 'Domestic',
                                        'price' => 55800,
                                        'currency' => 'INR',
                                        'change_percent' => '+2.0%',
                                        'arrow' => 'up',
                                        'url' => '/price/1101011',
                                    ],
                                    [
                                        'country' => 'India',
                                        'size_grade' => '1.0mm, CRCA',
                                        'trade_type' => 'Domestic',
                                        'price' => 56400,
                                        'currency' => 'INR',
                                        'change_percent' => '+1.1%',
                                        'arrow' => 'up',
                                        'url' => '/price/1101011',
                                    ],
                                ],
                            ],
                        ],
                    ],
                    ['commodity' => 'Mining', 'assessment_count' => 86, 'tag_market' => 'Ferrous'],
                    ['commodity' => 'Power', 'assessment_count' => 54, 'tag_market' => 'Energy'],
                    ['commodity' => 'Automobile', 'assessment_count' => 38, 'tag_market' => 'Manufacturing'],
                    ['commodity' => 'Construction', 'assessment_count' => 29, 'tag_market' => 'Infrastructure'],
                    ['commodity' => 'Shipbuilding', 'assessment_count' => 18, 'tag_market' => 'Maritime'],
                    ['commodity' => 'Oil & Gas', 'assessment_count' => 52, 'tag_market' => 'Energy'],
                    ['commodity' => 'Infrastructure', 'assessment_count' => 38, 'tag_market' => 'Development'],
                ],
            ],
        ], 200);
    }

    public function newsFeatured(Request $request)
    {
        $p = V2026LegacyBridge::paginationParams($request);
        $filters = V2026LegacyBridge::legacyFilters($request);
        /**
         * Route: featured news → v2019 insights listing.
         * Default source `home` matches getInsightsRows() home feed (DEFAULT_LIMIT_HOME), not generic `listing`.
         * Override with ?source=listing|commodity|… or pass ?filters={"featuredTab":"top"} etc. when the app expects it.
         */
        $post = [
            'resourceType' => 'app',
            'source' => $request->query('source', 'home'),
            'pageValue' => $p['page'],
            'filters' => $filters,
        ];

        return $this->v2019Post(
            $request,
            \App\Http\Controllers\v2019\InsightsController::class,
            'getInsights',
            $post,
            ['client_paginate' => true]
        );
    }

    public function newsIndustrySnapshot(Request $request)
    {
        $p = V2026LegacyBridge::paginationParams($request);
        $filters = V2026LegacyBridge::legacyFilters($request);
        $post = [
            'resourceType' => 'app',
            'source' => $request->query('source', 'listing'),
            'pageValue' => $p['page'],
            'filters' => $filters,
        ];

        return $this->v2019Post(
            $request,
            \App\Http\Controllers\v2019\IntelController::class,
            'getIntel',
            $post,
            ['client_paginate' => true]
        );
    }

    public function newsTranslations(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Converted successfully',
            'data' => [
                'original' => 'news',
                'converted' => 'converted news',
            ],
        ], 200);
    }

    public function newsAudio(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Audio generated successfully',
            'data' => [
                'news_id' => (int) $id,
                'title' => 'Global iron ore exports show divergent trends',
                'audio_url' => 'https://cdn.example.com/audio/news_101_en.mp3',
                'duration' => '00:02:45',
                'language' => 'en',
                'translated' => true,
                'generated_at' => '2026-03-19T16:30:00Z',
            ],
        ], 200);
    }

    public function newsCategories(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'market_id' => 'sometimes|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Category filters fetched successfully',
            'data' => [
                'filter_type' => 'category',
                'categories' => [
                    ['id' => 0, 'label' => 'All', 'slug' => 'all'],
                    ['id' => 1, 'label' => 'Intel', 'slug' => 'intel'],
                    ['id' => 2, 'label' => 'Insights', 'slug' => 'insights'],
                    ['id' => 3, 'label' => 'Market', 'slug' => 'market'],
                ],
            ],
        ], 200);
    }

    public function commoditiesOverview(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->query(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            'include' => 'sometimes|string|max:200',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Commodity overview fetched successfully',
            'data' => [
                'commodity_id' => (int) $id,
                'include' => $request->query('include'),
                'tabs' => [
                    ['key' => 'prices', 'label' => 'Prices', 'enabled' => true],
                    ['key' => 'news', 'label' => 'News', 'enabled' => true],
                    ['key' => 'tenders', 'label' => 'Tenders', 'enabled' => true],
                    ['key' => 'reports', 'label' => 'Reports', 'enabled' => true],
                ],
            ],
        ], 200);
    }

    public function commoditiesPrices(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->query(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            'currency' => 'sometimes|in:INR,USD,EUR,GBP,JPY,CNY',
            'category' => 'sometimes|in:ALL,DOM,IMP,EXP',
            'region' => 'sometimes|in:ALL,INDIA,INTL,CHINA',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        $p = V2026LegacyBridge::paginationParams($request);
        $filters = V2026LegacyBridge::legacyFilters($request);
        $filters['commodityID'] = array_values(array_unique(array_merge(
            (array) ($filters['commodityID'] ?? []),
            [(int) $id]
        )));

        /**
         * v2019 PricesController@getPrices → ApiQuery::getPricesRows expects filter keys
         * tradeType / priceType / selected_market (see pre_function/ApiQuery.php ~6100, ~6215).
         * Route id is the commodity master id; it is always merged into filters.commodityID.
         */
        if (! array_key_exists('selected_market', $filters)) {
            $filters['selected_market'] = '';
        }
        if (! array_key_exists('BlankMarketFlagHandler', $filters)) {
            $filters['BlankMarketFlagHandler'] = '';
        }

        $category = strtoupper((string) $request->query('category', 'ALL'));
        if (empty($filters['tradeType'])) {
            if ($category === 'IMP') {
                $filters['tradeType'] = 'import';
            } elseif ($category === 'EXP') {
                $filters['tradeType'] = 'export';
            } else {
                $filters['tradeType'] = 'domestic';
            }
        }
        if (empty($filters['priceType'])) {
            $tt = strtolower((string) $filters['tradeType']);
            if ($tt === 'import' || $tt === 'cnf') {
                $filters['priceType'] = 'cnf';
            } elseif ($tt === 'export' || $tt === 'fob') {
                $filters['priceType'] = 'fob';
            } else {
                $filters['priceType'] = 'f';
            }
        }

        $post = [
            'resourceType' => 'app',
            'source' => $request->query('source', 'commoditywise'),
            'pageValue' => $p['page'],
            'filters' => $filters,
        ];
        if ($request->has('currency')) {
            $post['currencyName'] = $request->query('currency');
        }

        return $this->v2019Post(
            $request,
            \App\Http\Controllers\v2019\PricesController::class,
            'getPrices',
            $post,
            []
        );
    }
    public function commoditiesNews(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->query(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            'industries' => 'sometimes|in:all,auto,construction,mining,infrastructure',
            'category' => 'sometimes|in:ALL,intel,DOM,IMP,EXP',
            'region' => 'sometimes|in:ALL,INDIA,INTL,CHINA',
            'Language' => 'sometimes|in:ALL,hindi,Bengali',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        $p = V2026LegacyBridge::paginationParams($request);
        $filters = V2026LegacyBridge::legacyFilters($request);
        $filters['commodityID'] = array_values(array_unique(array_merge(
            (array) ($filters['commodityID'] ?? []),
            [(int) $id]
        )));

        $post = [
            'resourceType' => 'app',
            'source' => $request->query('source', 'listing'),
            'pageValue' => $p['page'],
            'filters' => $filters,
        ];

        return $this->v2019Post(
            $request,
            \App\Http\Controllers\v2019\IntelController::class,
            'getIntel',
            $post,
            ['client_paginate' => true]
        );
    }
    public function commoditiesTenders(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->query(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            'filter_type' => 'sometimes|in:ALL,Buy,Sell,Services',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        $p = V2026LegacyBridge::paginationParams($request);
        $limit = defined('DEFAULT_TENDERS_LIMIT') ? (int) constant('DEFAULT_TENDERS_LIMIT') : 15;
        $filters = V2026LegacyBridge::legacyFilters($request);
        $filters['commodityID'] = array_values(array_unique(array_merge(
            (array) ($filters['commodityID'] ?? []),
            [(int) $id]
        )));
        if ($request->has('filter_type') && $request->query('filter_type') !== 'ALL') {
            $filters['tender_type'] = $request->query('filter_type');
        }

        $post = [
            'resourceType' => 'app',
            'source' => 'listing',
            'pageValue' => $p['page'],
            'filters' => $filters,
        ];
        $raw = V2026LegacyBridge::invoke($request, \App\Http\Controllers\v2019\TendersController::class, 'getTenders', $post);
        $norm = V2026LegacyBridge::normalizeEnvelope($raw);
        $cnt = is_array($norm['data']) ? count($norm['data']) : 0;
        $serverMeta = V2026LegacyBridge::serverPageMeta($p['page'], $p['per_page'], $cnt, $limit);

        return V2026LegacyBridge::respondFromLegacy($raw, $request, ['server_meta' => $serverMeta]);
    }
    public function commoditiesReports(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->query(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            'industries' => 'sometimes|in:all,auto,construction,mining,infrastructure',
            'category' => 'sometimes|in:ALL,intel,DOM,IMP,EXP',
            'region' => 'sometimes|in:ALL,INDIA,INTL,CHINA',
            'Language' => 'sometimes|in:ALL,hindi,Bengali',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        $selectedIndustry = $request->query('industries', 'all');
        $selectedCategory = $request->query('category', 'ALL');
        $selectedRegion = $request->query('region', 'ALL');
        $selectedLanguage = $request->query('Language', 'ALL');

        $industryLabelMap = [
            'all' => 'All Industries',
            'auto' => 'Auto',
            'construction' => 'Construction',
            'mining' => 'Mining',
            'infrastructure' => 'Infrastructure',
        ];

        return Response::json([
            'status' => true,
            'message' => 'Report list fetched successfully',
            'data' => [
                'filters' => [
                    'industries' => [
                        'selected' => isset($industryLabelMap[$selectedIndustry]) ? $industryLabelMap[$selectedIndustry] : 'All Industries',
                        'options' => [
                            ['code' => 'all', 'name' => 'All Industries'],
                            ['code' => 'auto', 'name' => 'Auto'],
                            ['code' => 'construction', 'name' => 'Construction'],
                            ['code' => 'mining', 'name' => 'Mining'],
                            ['code' => 'infrastructure', 'name' => 'Infrastructure'],
                        ],
                    ],
                    'category' => [
                        'selected' => $selectedCategory,
                        'options' => [
                            ['key' => 'intel', 'label' => 'Intel', 'description' => 'Market intelligence'],
                            ['key' => 'DOM', 'label' => 'Analysis', 'description' => 'Expert analysis'],
                            ['key' => 'IMP', 'label' => 'Featured', 'description' => 'Editor picks'],
                            ['key' => 'EXP', 'label' => 'Insights', 'description' => 'Deep dives'],
                        ],
                    ],
                    'region' => [
                        'selected' => $selectedRegion,
                        'options' => [
                            ['key' => 'ALL', 'label' => 'All Regions'],
                            ['key' => 'INDIA', 'label' => 'India', 'description' => 'Domestic markets'],
                            ['key' => 'INTL', 'label' => 'International', 'description' => 'Import & global'],
                            ['key' => 'CHINA', 'label' => 'China'],
                        ],
                    ],
                    'Language' => [
                        'selected' => $selectedLanguage,
                        'options' => [
                            ['key' => 'hindi', 'label' => 'Hindi', 'description' => 'हिन्दी'],
                            ['key' => 'Bengali', 'label' => 'Bengali', 'description' => 'বাংলা'],
                        ],
                    ],
                ],
                'market' => 'Ferrous',
                'items' => [
                    [
                        'commodity' => 'Iron Ore',
                        'sub_commodity' => 'fines/lumps',
                        'report_id' => 501,
                        'title' => 'India Iron Ore Market Outlook 2026',
                        'detail_link' => 'https://example.com/report/iron-ore-2026',
                        'date' => '29 January 2026',
                        'features' => [
                            'ai_analysis_enabled' => true,
                            'ai_label' => 'AI Analysis & Summarization',
                        ],
                        'actions' => [
                            'archives' => [
                                'label' => 'Archives',
                                'icon' => 'eye_icon',
                            ],
                            'share' => [
                                'label' => 'Share',
                                'icon' => 'share_nodes_icon',
                                'url' => 'https://example.com/share/daily-report-29-jan',
                            ],
                            'save' => [
                                'label' => 'Save',
                                'icon' => 'bookmark_icon',
                                'is_saved' => false,
                            ],
                        ],
                    ],
                    [
                        'commodity' => 'Iron Ore',
                        'sub_commodity' => 'fines/lumps',
                        'report_id' => 501,
                        'title' => 'India Iron Ore Market Outlook 2026',
                        'detail_link' => 'https://example.com/report/iron-ore-2026',
                        'date' => '29 January 2026',
                        'features' => [
                            'ai_analysis_enabled' => true,
                            'ai_label' => 'AI Analysis & Summarization',
                        ],
                        'actions' => [
                            'archives' => [
                                'label' => 'Archives',
                                'icon' => 'eye_icon',
                            ],
                            'share' => [
                                'label' => 'Share',
                                'icon' => 'share_nodes_icon',
                                'url' => 'https://example.com/share/daily-report-29-jan',
                            ],
                            'save' => [
                                'label' => 'Save',
                                'icon' => 'bookmark_icon',
                                'is_saved' => false,
                            ],
                        ],
                    ],
                    [
                        'commodity' => 'Iron Ore',
                        'sub_commodity' => 'fines/lumps',
                        'report_id' => 501,
                        'title' => 'India Iron Ore Market Outlook 2026',
                        'detail_link' => 'https://example.com/report/iron-ore-2026',
                        'date' => '29 January 2026',
                        'features' => [
                            'ai_analysis_enabled' => true,
                            'ai_label' => 'AI Analysis & Summarization',
                        ],
                        'actions' => [
                            'archives' => [
                                'label' => 'Archives',
                                'icon' => 'eye_icon',
                            ],
                            'share' => [
                                'label' => 'Share',
                                'icon' => 'share_nodes_icon',
                                'url' => 'https://example.com/share/daily-report-29-jan',
                            ],
                            'save' => [
                                'label' => 'Save',
                                'icon' => 'bookmark_icon',
                                'is_saved' => false,
                            ],
                        ],
                    ],
                    [
                        'commodity' => 'Iron Ore',
                        'sub_commodity' => 'fines/lumps',
                        'report_id' => 501,
                        'title' => 'India Iron Ore Market Outlook 2026',
                        'detail_link' => 'https://example.com/report/iron-ore-2026',
                        'date' => '29 January 2026',
                        'features' => [
                            'ai_analysis_enabled' => true,
                            'ai_label' => 'AI Analysis & Summarization',
                        ],
                        'actions' => [
                            'archives' => [
                                'label' => 'Archives',
                                'icon' => 'eye_icon',
                            ],
                            'share' => [
                                'label' => 'Share',
                                'icon' => 'share_nodes_icon',
                                'url' => 'https://example.com/share/daily-report-29-jan',
                            ],
                            'save' => [
                                'label' => 'Save',
                                'icon' => 'bookmark_icon',
                                'is_saved' => false,
                            ],
                        ],
                    ],
                    [
                        'commodity' => 'Iron Ore',
                        'sub_commodity' => 'fines/lumps',
                        'report_id' => 501,
                        'title' => 'India Iron Ore Market Outlook 2026',
                        'detail_link' => 'https://example.com/report/iron-ore-2026',
                        'date' => '29 January 2026',
                        'features' => [
                            'ai_analysis_enabled' => true,
                            'ai_label' => 'AI Analysis & Summarization',
                        ],
                        'actions' => [
                            'archives' => [
                                'label' => 'Archives',
                                'icon' => 'eye_icon',
                            ],
                            'share' => [
                                'label' => 'Share',
                                'icon' => 'share_nodes_icon',
                                'url' => 'https://example.com/share/daily-report-29-jan',
                            ],
                            'save' => [
                                'label' => 'Save',
                                'icon' => 'bookmark_icon',
                                'is_saved' => false,
                            ],
                        ],
                    ],
                ],
            ],
        ], 200);
    }

    public function userPasswordUpdate(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'current_password' => 'required|string|min:6',
            'new_password' => 'required|string|min:6',
            'confirm_password' => 'required|string|same:new_password',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Password changed successfully.',
            'data' => null,
        ], 200);
    }

    public function userNotificationPreferencesShow(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Notification preferences fetched successfully.',
            'data' => [
                'commodity_preferences' => [
                    'label' => 'Commodity Preferences',
                    'description' => 'Select commodities you want to track',
                    'options' => [
                        ['id' => 1, 'name' => 'Iron Ore', 'is_selected' => true],
                        ['id' => 2, 'name' => 'Steel', 'is_selected' => true],
                        ['id' => 3, 'name' => 'Sponge Iron', 'is_selected' => true],
                        ['id' => 4, 'name' => 'Pellet', 'is_selected' => false],
                        ['id' => 5, 'name' => 'HR Coil', 'is_selected' => true],
                        ['id' => 6, 'name' => 'CR Coil', 'is_selected' => false],
                        ['id' => 7, 'name' => 'Wire Rod', 'is_selected' => false],
                        ['id' => 8, 'name' => 'TMT Bar', 'is_selected' => false],
                        ['id' => 9, 'name' => 'Billet', 'is_selected' => false],
                        ['id' => 10, 'name' => 'Coal', 'is_selected' => true],
                    ],
                ],
                'region_preferences' => [
                    'label' => 'Region Preferences',
                    'description' => 'Select regions you want to follow',
                    'options' => [
                        ['id' => 1, 'name' => 'India', 'is_selected' => true],
                        ['id' => 2, 'name' => 'China', 'is_selected' => true],
                        ['id' => 3, 'name' => 'South East Asia', 'is_selected' => false],
                        ['id' => 4, 'name' => 'Middle East', 'is_selected' => false],
                        ['id' => 5, 'name' => 'Europe', 'is_selected' => false],
                        ['id' => 6, 'name' => 'CIS', 'is_selected' => false],
                        ['id' => 7, 'name' => 'North America', 'is_selected' => false],
                        ['id' => 8, 'name' => 'South America', 'is_selected' => false],
                        ['id' => 9, 'name' => 'Africa', 'is_selected' => false],
                        ['id' => 10, 'name' => 'Australia', 'is_selected' => false],
                    ],
                ],
            ],
        ], 200);
    }

    public function userNotificationPreferencesUpdate(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'commodity_preferences' => 'required|array',
            'commodity_preferences.*' => 'integer|min:1',
            'region_preferences' => 'required|array',
            'region_preferences.*' => 'integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        $selectedCommodities = $request->input('commodity_preferences', []);
        $selectedRegions = $request->input('region_preferences', []);

        $commodityOptions = [
            ['id' => 1, 'name' => 'Iron Ore'],
            ['id' => 2, 'name' => 'Steel'],
            ['id' => 3, 'name' => 'Sponge Iron'],
            ['id' => 4, 'name' => 'Pellet'],
            ['id' => 5, 'name' => 'HR Coil'],
            ['id' => 6, 'name' => 'CR Coil'],
            ['id' => 7, 'name' => 'Wire Rod'],
            ['id' => 8, 'name' => 'TMT Bar'],
            ['id' => 9, 'name' => 'Billet'],
            ['id' => 10, 'name' => 'Coal'],
        ];

        $regionOptions = [
            ['id' => 1, 'name' => 'India'],
            ['id' => 2, 'name' => 'China'],
            ['id' => 3, 'name' => 'South East Asia'],
            ['id' => 4, 'name' => 'Middle East'],
            ['id' => 5, 'name' => 'Europe'],
            ['id' => 6, 'name' => 'CIS'],
            ['id' => 7, 'name' => 'North America'],
            ['id' => 8, 'name' => 'South America'],
            ['id' => 9, 'name' => 'Africa'],
            ['id' => 10, 'name' => 'Australia'],
        ];

        $commodityOptions = array_map(function ($opt) use ($selectedCommodities) {
            $opt['is_selected'] = in_array((int) $opt['id'], array_map('intval', $selectedCommodities), true);
            return $opt;
        }, $commodityOptions);

        $regionOptions = array_map(function ($opt) use ($selectedRegions) {
            $opt['is_selected'] = in_array((int) $opt['id'], array_map('intval', $selectedRegions), true);
            return $opt;
        }, $regionOptions);

        return Response::json([
            'status' => true,
            'message' => 'Notification preferences updated successfully.',
            'data' => [
                'commodity_preferences' => [
                    'label' => 'Commodity Preferences',
                    'description' => 'Select commodities you want to track',
                    'options' => $commodityOptions,
                ],
                'region_preferences' => [
                    'label' => 'Region Preferences',
                    'description' => 'Select regions you want to follow',
                    'options' => $regionOptions,
                ],
            ],
        ], 200);
    }

    public function reportsShow(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Report fetched successfully',
            'data' => [
                'item_id' => 14031,
                'report_id' => 3,
                'order_for_regular_rpts' => 6,
                'package_id' => 0,
                'cover_image_url' => 'https://bigmint-reports.s3.ap-south-1.amazonaws.com/images/3/1.jpg',
                'title' => 'Coal Monthly Review: April 2026',
                'date_published' => '10 Apr 2026',
                'date_published_formatted' => '2026-04-10',
                'time_to_read' => 'hidden',
                'commodity_name' => 'Coal',
                'sub_commodity_name' => '',
                'commodity_id' => '401',
                'sub_commodity_id' => '0',
                'main_file_url' => 'hidden',
                'sample_file_url' => 'https://www.bigmint.co/reportsDnld.php?p=UERGcy8zLzIwMjYvMDQvQ29hbF9Nb250aGx5X1Jldmlld19KYW4yMDI2XzE3NjgwMzI0OTAxNTZfNzEwLnBkZg==',
                'type_of_report' => 'regular',
                'description' => "<li>Monthy Comparison of Indian Coal Import</li>\r\n<li>International Coal Market and Prices</li>\r\n<li>Coking Coal Price Trend</li>\r\n<li>CIL's Coal Production and Offtake</li>",
                'is_bookmarked' => 'n',
                'is_added_to_portfolio' => 'n',
                'author_details' => [
                    'author_id' => 194,
                    'image_url' => '',
                    'name' => 'Damini Sahu',
                    'email_id' => 'damini@steelmintgroup.com',
                    'social_accounts' => [
                        'facebook' => '',
                        'twitter' => '',
                        'linked_in' => '',
                    ],
                    'about_author' => '',
                ],
            ],
        ], 200);
    }

    public function reportsAiAnalysis(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->all(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            'query' => 'required|string|max:2000',
            'language' => 'required|string|max:10',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'AI analysis generated successfully',
            'data' => [
                'report_id' => (int) $id,
                'query' => $request->input('query'),
                'language' => $request->input('language'),
                'summary' => null,
                'response' => 'The report highlights that the Indian steel market remained strong in January 2026 due to steady demand from infrastructure and auto sectors. Prices increased by ₹300-500/MT across major regions',
                'generated_at' => date('c')
            ],
        ], 200);
    }
    //done iss se upr
    public function reportsSample(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Sample report fetched successfully',
            'data' => [
                'report_id' => (int) $id,
                'sample_available' => true,
            ],
        ], 200);
    }

    public function reportsArchives(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Report archives fetched successfully',
            'data' => [
                'report_id' => (int) $id,
                'archives' => [],
            ],
        ], 200);
    }

    public function reportsCategories(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Report categories fetched successfully',
            'data' => [
                'categories' => [],
            ],
        ], 200);
    }

    public function tendersDocuments(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Tender documents fetched successfully',
            'data' => [
                'tender_id' => (int) $id,
                'documents' => [
                    [
                        'id' => 101,
                        'title' => 'Tender Notice Document',
                        'file_name' => 'tender_notice.pdf',
                        'file_type' => 'pdf',
                        'file_size' => '2.5 MB',
                        'download_url' => 'https://cdn.example.com/tenders/' . (int) $id . '/tender_notice.pdf',
                        'uploaded_at' => '2026-03-18T10:00:00Z',
                    ],
                    [
                        'id' => 102,
                        'title' => 'Technical Specification',
                        'file_name' => 'technical_spec.docx',
                        'file_type' => 'docx',
                        'file_size' => '1.2 MB',
                        'download_url' => 'https://cdn.example.com/tenders/' . (int) $id . '/technical_spec.docx',
                        'uploaded_at' => '2026-03-18T11:30:00Z',
                    ],
                    [
                        'id' => 103,
                        'title' => 'Price Bid Format',
                        'file_name' => 'price_bid.xlsx',
                        'file_type' => 'xlsx',
                        'file_size' => '800 KB',
                        'download_url' => 'https://cdn.example.com/tenders/' . (int) $id . '/price_bid.xlsx',
                        'uploaded_at' => '2026-03-18T12:00:00Z',
                    ],
                ],
            ],
        ], 200);
    }

    public function tendersDocumentDownload(Request $request, $id, $docId)
    {
        $validator = Validator::make(['id' => $id, 'docId' => $docId], [
            'id' => 'required|integer|min:1',
            'docId' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        $fileName = ((int) $docId === 101) ? 'tender_notice.pdf' : ('document_' . (int) $docId . '.pdf');

        return Response::json([
            'status' => true,
            'message' => 'Document download link generated',
            'data' => [
                'tender_id' => (int) $id,
                'document_id' => (int) $docId,
                'file_name' => $fileName,
                'download_url' => 'https://cdn.example.com/tenders/' . (int) $id . '/' . $fileName,
                'expires_at' => '2026-03-20T18:00:00Z',
            ],
        ], 200);
    }

    public function tendersRecent(Request $request)
    {
        $p = V2026LegacyBridge::paginationParams($request);
        $limit = defined('DEFAULT_TENDERS_LIMIT') ? (int) constant('DEFAULT_TENDERS_LIMIT') : 15;
        $post = [
            'resourceType' => 'app',
            'source' => 'listing',
            'pageValue' => $p['page'],
            'filters' => V2026LegacyBridge::legacyFilters($request),
        ];
        $raw = V2026LegacyBridge::invoke($request, \App\Http\Controllers\v2019\TendersController::class, 'getTenders', $post);
        $norm = V2026LegacyBridge::normalizeEnvelope($raw);
        $cnt = is_array($norm['data']) ? count($norm['data']) : 0;
        $serverMeta = V2026LegacyBridge::serverPageMeta($p['page'], $p['per_page'], $cnt, $limit);

        return V2026LegacyBridge::respondFromLegacy($raw, $request, ['server_meta' => $serverMeta]);
    }

    public function tendersMap(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'market_id' => 'sometimes|integer|min:1',
            'tender_type' => 'sometimes|string|max:50',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        $p = V2026LegacyBridge::paginationParams($request);
        $limit = defined('DEFAULT_TENDERS_LIMIT') ? (int) constant('DEFAULT_TENDERS_LIMIT') : 15;
        $filters = V2026LegacyBridge::legacyFilters($request);
        if ($request->has('market_id')) {
            $filters['commodityID'] = array_merge((array) ($filters['commodityID'] ?? []), [(int) $request->query('market_id')]);
        }
        if ($request->has('tender_type')) {
            $filters['tender_type'] = $request->query('tender_type');
        }
        $post = [
            'resourceType' => 'app',
            'source' => $request->query('source', 'listing'),
            'pageValue' => $p['page'],
            'filters' => $filters,
        ];
        $raw = V2026LegacyBridge::invoke($request, \App\Http\Controllers\v2019\TendersController::class, 'getTenders', $post);
        $norm = V2026LegacyBridge::normalizeEnvelope($raw);
        $cnt = is_array($norm['data']) ? count($norm['data']) : 0;
        $serverMeta = V2026LegacyBridge::serverPageMeta($p['page'], $p['per_page'], $cnt, $limit);

        return V2026LegacyBridge::respondFromLegacy($raw, $request, ['server_meta' => $serverMeta]);
    }

    public function tendersMapFilters(Request $request)
    {
        return $this->v2019Post($request, \App\Http\Controllers\v2019\TendersController::class, 'getTendersFilter', [
            'resourceType' => $request->query('resourceType', 'app'),
        ], []);
    }

    public function eventsBookingInitiate(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->all(), ['id' => $id]), [
            'package_id' => 'required|integer|min:1',
            'package_type' => 'required|string|max:50',
            'delegates' => 'required|integer|min:1',
            'price_per_delegate' => 'required|numeric|min:0',
            'total_amount' => 'required|numeric|min:0',
            'currency' => 'required|string|max:10',
            'mobile_number' => 'required|string|max:20',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Booking initiated successfully',
            'data' => [
                'event_id' => (int) $id,
                'booking_id' => 'EVT' . (string) (time() % 100000000),
                'otp_sent' => true,
                'mobile_number' => $request->input('mobile_number'),
                'otp_expires_at' => date('c', time() + 300),
            ],
        ], 200);
    }

    public function eventsBookingVerifyOtp(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->all(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            'booking_id' => 'required|string|max:50',
            'otp' => 'required|string|max:10',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'OTP verified successfully',
            'data' => [
                'event_id' => (int) $id,
                'booking_id' => $request->input('booking_id'),
                'verified' => true,
            ],
        ], 200);
    }

    public function eventsBookingVerifyPayment(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->all(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            'transaction_id' => 'required|string|max:100',
            'booking_id' => 'required|string|max:50',
            'razorpay_order_id' => 'required|string|max:100',
            'razorpay_payment_id' => 'required|string|max:100',
            'razorpay_signature' => 'required|string|max:255',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Payment verified and booking confirmed',
            'data' => [
                'transaction_id' => $request->input('transaction_id'),
                'booking_id' => $request->input('booking_id'),
                'payment' => [
                    'order_id' => $request->input('razorpay_order_id'),
                    'payment_id' => $request->input('razorpay_payment_id'),
                    'status' => 'paid',
                    'amount' => 28000,
                    'currency' => 'INR',
                ],
                'booking' => [
                    'event_id' => (int) $id,
                    'delegates' => 2,
                    'status' => 'confirmed',
                ],
            ],
        ], 200);
    }

    public function eventsBookingSubmitAndPay(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Booking submitted and payment initiated successfully',
            'data' => [
                'event_id' => (int) $id,
                'payment_gateway' => 'razorpay',
                'order_id' => null,
            ],
        ], 200);
    }

    public function eventsBookingOrderDetails(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Order details fetched successfully',
            'data' => [
                'event_id' => (int) $id,
                'breakdown' => [],
            ],
        ], 200);
    }

    public function mediaIndex(Request $request)
    {
        $validator = Validator::make($request->query(), [
            // Laravel 5.1 does not support the `nullable` rule (validateNullable doesn't exist).
            // Since `type` is optional, just validate `in:` when it is provided.
            'type' => 'in:video,short,photo-story,podcast',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Media fetched successfully',
            'data' => [
                'shorts' => [
                    'items' => [
                        [
                            'id' => 1,
                            'thumbnail_image' => 'https://picsum.photos/id/101/400/700',
                            'video_link' => 'https://example.com/videos/shorts/hrc-price-1.mp4',
                            'heading' => 'HRC Price Flash: Feb Week 3',
                        ],
                        [
                            'id' => 2,
                            'thumbnail_image' => 'https://picsum.photos/id/102/400/700',
                            'video_link' => 'https://example.com/videos/shorts/iron-ore-2.mp4',
                            'heading' => 'Iron Ore Weekly Wrap-up',
                        ],
                        [
                            'id' => 3,
                            'thumbnail_image' => 'https://picsum.photos/id/103/400/700',
                            'video_link' => 'https://example.com/videos/shorts/copper-3.mp4',
                            'heading' => 'Copper Delhi News Update',
                        ],
                    ],
                ],
                'videos' => [
                    'items' => [
                        [
                            'media_id' => 1,
                            'title' => 'Steel Price Forecast: Expert Panel Discussion',
                            'thumbnail_url' => 'https://example.com/thumb1.png',
                            'embed_link' => 'https://www.youtube.com/embed/dQw4w9WgXcQ',
                            'media_type_label' => 'Live',
                            'organizer' => 'Bigmint',
                            'views' => '1.2k',
                            'read_time' => '5 min read',
                        ],
                        [
                            'media_id' => 2,
                            'title' => 'Market pulse Weekly Ep. 42',
                            'thumbnail_url' => 'https://example.com/thumb2.png',
                            'embed_link' => 'https://www.youtube.com/embed/3tmd-ClpJxA',
                            'media_type_label' => 'Podcast',
                            'organizer' => 'Bigmint',
                            'views' => '1.5k',
                            'read_time' => '15 min read',
                        ],
                        [
                            'media_id' => 3,
                            'title' => 'Global Coal Supply Chain Analysis 2026',
                            'thumbnail_url' => 'https://example.com/thumb3.png',
                            'embed_link' => 'https://www.youtube.com/embed/example3',
                            'media_type_label' => 'Webinar',
                            'organizer' => 'Bigmint',
                            'views' => '900',
                            'read_time' => '8 min read',
                        ],
                    ],
                ],
                'images' => [
                    'items' => [
                        [
                            'image_id' => 1,
                            'title' => 'India Steel Production Overview FY26',
                            'banner_image' => 'https://picsum.photos/id/301/600/400',
                            'image_count' => '3 Images',
                            'published_date' => '18 Feb 2026',
                            'views' => '3.4K views',
                            'details_link' => 'https://example.com/media/images/1',
                        ],
                        [
                            'image_id' => 2,
                            'title' => 'Global Aluminium Trade Flow Map',
                            'banner_image' => 'https://picsum.photos/id/302/600/400',
                            'image_count' => '2 Images',
                            'published_date' => '15 Feb 2026',
                            'views' => '1.8K views',
                            'details_link' => 'https://example.com/media/images/2',
                        ],
                        [
                            'image_id' => 3,
                            'title' => 'Coal Mining Operations Gallery',
                            'banner_image' => 'https://picsum.photos/id/303/600/400',
                            'image_count' => '5 Images',
                            'published_date' => '10 Feb 2026',
                            'views' => '2.1K views',
                            'details_link' => 'https://example.com/media/images/3',
                        ],
                    ],
                ],
                'filters' => [
                    'commodity' => [
                        ['id' => 0, 'label' => 'All', 'slug' => 'all'],
                        ['id' => 1, 'label' => 'Steel', 'slug' => 'steel'],
                        ['id' => 2, 'label' => 'Iron Ore', 'slug' => 'iron-ore'],
                        ['id' => 3, 'label' => 'Coal', 'slug' => 'coal'],
                        ['id' => 4, 'label' => 'Non-Ferrous', 'slug' => 'non-ferrous'],
                        ['id' => 5, 'label' => 'Copper', 'slug' => 'copper'],
                        ['id' => 6, 'label' => 'Sponge Iron', 'slug' => 'sponge-iron'],
                    ],
                    'region' => [
                        ['id' => 0, 'label' => 'All', 'slug' => 'all'],
                        ['id' => 1, 'label' => 'India', 'slug' => 'india'],
                        ['id' => 2, 'label' => 'Global', 'slug' => 'global'],
                    ],
                    'category' => [
                        ['label' => 'All', 'slug' => 'all'],
                        ['label' => 'Shorts', 'slug' => 'shorts'],
                        ['label' => 'Videos', 'slug' => 'videos'],
                        ['label' => 'Images', 'slug' => 'images'],
                    ],
                ],
            ],
        ], 200);
    }

    public function mediaShow(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Media details fetched successfully',
            'data' => [
                'video_details' => [
                    'media_id' => (int) $id,
                    'title' => 'Steel Price Forecast: Expert Panel Discussion',
                    'embed_link' => 'https://www.youtube.com/embed/dQw4w9WgXcQ',
                    'thumbnail_image' => 'https://example.com/thumb1.png',
                    'media_type_label' => 'Live',
                    'organizer' => 'Bigmint',
                    'published_date' => '29 Jan 2026',
                    'views' => '1.2k views',
                    'duration' => '12:34',
                    'read_time' => '5 min read',
                    'description' => "BigMint's expert panel discusses the steel price forecast for 2026, covering domestic and global market trends.",
                    'actions' => [
                        'is_liked' => false,
                        'is_saved' => false,
                        'download_url' => 'https://example.com/download/media/' . (int) $id,
                    ],
                ],
                'image_details' => [
                    'image_id' => 1,
                    'title' => 'India Steel Production Overview FY26',
                    'description' => 'Detailed visual analysis of steel production across different regions in India for the fiscal year 2026.',
                    'published_date' => '18 Feb 2026',
                    'views' => '3.4K views',
                    'items' => [
                        ['image_url' => 'https://picsum.photos/id/10/1200/800'],
                        ['image_url' => 'https://picsum.photos/id/11/1200/800'],
                        ['image_url' => 'https://picsum.photos/id/12/1200/800'],
                    ],
                ],
            ],
        ], 200);
    }

    public function mediaView(Request $request, $id)
    {
        $validator = Validator::make(array_merge($request->all(), ['id' => $id]), [
            'id' => 'required|integer|min:1',
            // Laravel 5.1 does not support the `nullable` rule.
            'media_id' => 'integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        if (!$request->has('media_id')) {
            $request->merge(['media_id' => (int) $id]);
        }

        return Response::json([
            'status' => true,
            'message' => 'View tracked successfully',
            'data' => [
                'media_id' => (int) $request->input('media_id', $id),
                'total_views' => '1.2k',
                'updated_at' => '2026-03-23 18:55:00',
            ],
        ], 200);
    }

    public function mediaRelated(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Related content fetched successfully',
            'data' => [
                'related_filters' => [
                    'commodity' => [
                        ['id' => 0, 'label' => 'All', 'commodity' => 'all'],
                        ['id' => 1, 'label' => 'Live', 'commodity' => 'live'],
                        ['id' => 2, 'label' => 'Podcast', 'commodity' => 'podcast'],
                        ['id' => 3, 'label' => 'Webinar', 'commodity' => 'webinar'],
                        ['id' => 4, 'label' => 'Interview', 'commodity' => 'interview'],
                    ],
                ],
                'items' => [
                    [
                        'media_id' => 202,
                        'title' => 'Coal Sector Analysis with Industry Experts',
                        'embed_link' => 'https://www.youtube.com/embed/dQw4w9WgXcQ',
                        'media_type_label' => 'live',
                        'thumbnail_image' => 'https://example.com/thumb1.png',
                        'duration_badge' => '28:15',
                        'published_date' => '28 Jan 2026',
                        'views' => '890 views',
                    ],
                    [
                        'media_id' => 203,
                        'title' => 'Iron Ore Price Forecast Q1 FY27',
                        'embed_link' => 'https://www.youtube.com/embed/dQw4w9WgXcQ',
                        'media_type_label' => 'podcast',
                        'thumbnail_image' => 'https://example.com/thumb1.png',
                        'duration_badge' => '18:42',
                        'published_date' => '27 Jan 2026',
                        'views' => '2.1K views',
                    ],
                    [
                        'media_id' => 206,
                        'title' => 'Steel Production Trends 2026',
                        'embed_link' => 'https://www.youtube.com/embed/dQw4w9WgXcQ',
                        'media_type_label' => 'webinar',
                        'thumbnail_image' => 'https://example.com/thumb1.png',
                        'duration_badge' => '15:10',
                        'published_date' => '26 Jan 2026',
                        'views' => '1.5K views',
                    ],
                    [
                        'media_id' => 206,
                        'title' => 'Steel Production Trends 2026',
                        'embed_link' => 'https://www.youtube.com/embed/dQw4w9WgXcQ',
                        'media_type_label' => 'interview',
                        'thumbnail_image' => 'https://example.com/thumb1.png',
                        'duration_badge' => '15:10',
                        'published_date' => '26 Jan 2026',
                        'views' => '1.5K views',
                    ],
                ],
            ],
        ], 200);
    }

    public function mediaCategories(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'category fetched successfully',
            'data' => [
                'category' => [
                    ['label' => 'All', 'slug' => 'all'],
                    ['label' => 'Shorts', 'slug' => 'shorts'],
                    ['label' => 'Videos', 'slug' => 'videos'],
                    ['label' => 'Images', 'slug' => 'images'],
                ],
            ],
        ], 200);
    }

    public function infographicsIndex(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Infographics listing fetched successfully',
            'data' => [
                'view_all_link' => 'https://example.com/infographics/all',
                'items' => [
                    [
                        'infographic_id' => 901,
                        'title' => 'India Steel Production 2025',
                        'source' => 'BigMint',
                        'date' => '8 Mar 2026',
                        'thumbnail_image' => 'https://example.com/images/infog_steel.png',
                        'detail_link' => 'https://example.com/share/infog/901',
                        'is_bookmarked' => false,
                    ],
                    [
                        'infographic_id' => 902,
                        'title' => 'Coal Supply Analysis',
                        'source' => 'BigMint',
                        'date' => '1 Mar 2026',
                        'thumbnail_image' => 'https://example.com/images/infog_steel.png',
                        'detail_link' => 'https://example.com/share/infog/901',
                        'is_bookmarked' => false,
                    ],
                ],
            ],
        ], 200);
    }

    public function infographicsShow(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Infographics details fetched successfully',
            'data' => [
                'commodity' => 'Ferrous',
                'sub_commodity' => 'Steel Production',
                'infographic_id' => 901,
                'title' => 'India Steel Production 2025',
                'source' => 'BigMint',
                'date' => '8 Mar 2026',
                'thumbnail_image' => 'https://example.com/images/infog_steel.png',
                'detail_link' => 'https://example.com/share/infog/901',
                'is_bookmarked' => false,
                'views' => '3.4K',
                'saves' => '1.2K',
                'statistics' => [
                    'total_production' => [
                        'title' => 'Total Production',
                        'value' => '143.6',
                        'unit' => 'MT',
                        'change' => '+6.2%',
                        'type' => 'YoY',
                    ],
                    'capacity_utilization' => [
                        'title' => 'Capacity Utilization',
                        'value' => '82.5',
                        'unit' => '%',
                        'change' => '+3.1%',
                        'type' => 'YoY',
                    ],
                    'domestic_demand' => [
                        'title' => 'Domestic Demand',
                        'value' => '128.4',
                        'unit' => 'MT',
                        'change' => '+8.0%',
                        'type' => 'YoY',
                    ],
                    'exports' => [
                        'title' => 'Exports',
                        'value' => '6.8',
                        'unit' => 'MT',
                        'change' => '-12.3%',
                        'type' => 'YoY',
                    ],
                ],
                'key_highlights' => [
                    [
                        'title' => "India's crude steel production",
                        'description' => "India's crude steel production reached 143.6 million tonnes in FY26, making it the second-largest producer globally after China.",
                    ],
                    [
                        'title' => 'Capacity expansion',
                        'description' => 'Capacity expansion continues with 15 MT of new capacity commissioned during the year, led by JSW Steel, Tata Steel, and SAIL.',
                    ],
                    [
                        'title' => 'Green steel initiatives',
                        'description' => 'Green steel initiatives gained momentum with hydrogen-based DRI projects announced by major producers, targeting 10% green steel by 2030.',
                    ],
                    [
                        'title' => 'Infrastructure push',
                        'description' => 'Infrastructure push from government spending drove domestic consumption growth, with construction sector accounting for 62% of steel demand.',
                    ],
                ],
                'description' => 'Infrastructure push from government spending drove domestic consumption growth, with construction sector accounting for 62% of steel demand. Infrastructure push from government spending drove domestic consumption growth, with construction sector accounting for 62% of steel demand.',
                'related_infographics' => [
                    [
                        'title' => 'Global Iron Ore Trade Map',
                        'date' => '25 Jan 2026',
                        'views' => '2.8K',
                    ],
                    [
                        'title' => 'India Coal Supply Chain Analysis',
                        'date' => '22 Jan 2026',
                        'views' => '1.8K',
                    ],
                ],
            ],
        ], 200);
    }

    public function infographicsFeatured(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Featured infographics fetched successfully',
            'data' => [
                'view_all_link' => 'https://example.com/infographics/all',
                'items' => [
                    [
                        'commodity' => 'Ferrous',
                        'sub_commodity' => 'Steel Production',
                        'infographic_id' => 901,
                        'title' => 'India Steel Production 2025',
                        'source' => 'BigMint',
                        'date' => '8 Mar 2026',
                        'thumbnail_image' => 'https://example.com/images/infog_steel.png',
                        'detail_link' => 'https://example.com/share/infog/901',
                        'is_bookmarked' => false,
                        'saves' => '1.2K',
                    ],
                    [
                        'commodity' => 'Ferrous',
                        'sub_commodity' => 'Steel Production',
                        'infographic_id' => 902,
                        'title' => 'India Steel Production 2025',
                        'source' => 'BigMint',
                        'date' => '8 Mar 2026',
                        'thumbnail_image' => 'https://example.com/images/infog_steel.png',
                        'detail_link' => 'https://example.com/share/infog/901',
                        'is_bookmarked' => false,
                        'saves' => '1.2K',
                    ],
                ],
            ],
        ], 200);
    }

    public function statisticsIndex(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Statistics listing fetched successfully',
            'data' => [
                'items' => [],
            ],
        ], 200);
    }

    public function statisticsShow(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Statistics detail fetched successfully',
            'data' => [
                'id' => (int) $id,
            ],
        ], 200);
    }

    public function statisticsRelatedInfographics(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Related infographics fetched successfully',
            'data' => [
                'statistics_id' => (int) $id,
                'items' => [],
            ],
        ], 200);
    }

    public function searchSuggestions(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Search suggestions fetched successfully',
            'data' => [
                'suggestions' => [],
            ],
        ], 200);
    }

    public function searchRecentIndex(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'limit' => 'sometimes|integer|min:1|max:100',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Recent searches fetched successfully',
            'data' => [
                [
                    'id' => 1,
                    'title' => 'iron ore price',
                    'type' => 'commodity',
                    'searched_at' => '2026-03-24T10:30:00Z',
                ],
                [
                    'id' => 2,
                    'title' => 'steel report',
                    'type' => 'report',
                    'searched_at' => '2026-03-24T09:50:00Z',
                ],
                [
                    'id' => 3,
                    'title' => 'coal tenders',
                    'type' => 'tender',
                    'searched_at' => '2026-03-23T18:20:00Z',
                ],
            ],
        ], 200);
    }

    public function searchRecentDestroy(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'type' => 'sometimes|in:all',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Recent searches cleared successfully',
            'data' => [
                'cleared' => true,
            ],
        ], 200);
    }

    public function searchRecentDestroyById(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Search entry deleted successfully',
            'data' => [
                'id' => (int) $id,
                'deleted' => true,
            ],
        ], 200);
    }

    public function notificationsReadStatus(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'all' => 'sometimes|boolean',
            'ids' => 'sometimes|array',
            'ids.*' => 'integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        $all = (bool) $request->input('all', false);
        $ids = $request->input('ids', []);

        // CSV contract: supports either {all:true} OR {ids:[...]}
        if (!$all && empty($ids)) {
            return Response::json([
                'status' => false,
                'message' => 'Validation error',
                'errors' => [
                    'all' => ['Either set all=true or provide ids array.'],
                ],
            ], 422);
        }

        return Response::json([
            'status' => true,
            'message' => 'Notifications read status updated successfully',
            'data' => [
                'all' => $all,
                'ids' => $all ? [] : $ids,
            ],
        ], 200);
    }

    public function notificationsUnreadCount(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Unread notification count fetched successfully',
            'data' => [
                'unread_count' => 3,
                'has_unread' => true,
                'last_checked_at' => '2026-03-24T17:30:00Z',
            ],
        ], 200);
    }

    public function analyticsEvents(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Analytics events received successfully',
            'data' => [
                'received' => is_array($request->all()) ? count($request->all()) : 0,
            ],
        ], 202);
    }

    public function recentlyViewedIndex(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'limit' => 'sometimes|integer|min:1|max:100',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Recently viewed items fetched successfully',
            'data' => [
                [
                    'commodity' => 'Soybean',
                    'sub_commodity' => 'FAQ Grade',
                    'sub_sub_commodity' => 'FAQ Grade',
                    'assessment_id' => '1068',
                    'title' => 'Soybean Indore Market',
                    'size_grade' => '2.5mm,IS 2062 E250',
                    'published_date' => '-',
                    'frequency' => 'D',
                    'currency' => 'INR',
                    'trade_type' => 'domestic',
                    'price' => '₹4,250',
                    'change' => ' +50 ',
                    'change_percent' => 1.2,
                    'previous_price' => '4200',
                    'arrow' => 'up',
                    '1W' => '₹4,100',
                    '1M' => '₹4,000',
                    '3M' => '₹4,300',
                ],
                [
                    'commodity' => 'Mustard Seed',
                    'sub_commodity' => 'Bold Grade',
                    'sub_sub_commodity' => 'Bold Grade',
                    'assessment_id' => '1069',
                    'title' => 'Mustard Jaipur Market',
                    'size_grade' => '2.5mm,IS 2062 E250',
                    'published_date' => '-',
                    'frequency' => 'D',
                    'currency' => 'INR',
                    'trade_type' => 'domestic',
                    'price' => '₹5,800',
                    'change' => ' -75 ',
                    'change_percent' => -1.3,
                    'previous_price' => '5875',
                    'arrow' => 'down',
                    '1W' => '₹5,900',
                    '1M' => '₹6,000',
                    '3M' => '₹5,700',
                ],
            ],
        ], 200);
    }

    public function recentlyViewedStore(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Recently viewed item recorded successfully',
            'data' => $request->all(),
        ], 201);
    }

    public function recentlyViewedDestroy(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Recently viewed items cleared successfully',
            'data' => [
                'cleared' => true,
            ],
        ], 200);
    }

    public function bookmarksIndex(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'type' => 'sometimes|in:news,reports,tenders,infographics',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Bookmarks fetched successfully',
            'data' => [
                'type' => $request->query('type'),
                'items' => [],
            ],
        ], 200);
    }

    public function alertsIndex(Request $request)
    {
        $validator = Validator::make($request->query(), [
            'type' => 'sometimes|in:price,tender',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Alerts fetched successfully',
            'data' => [
                'type' => $request->query('type'),
                'items' => [],
            ],
        ], 200);
    }

    public function alertsStore(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'alertType' => 'sometimes|in:price,tender',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Alert created successfully',
            'data' => $request->all(),
        ], 201);
    }

    public function alertsToggle(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Alert toggled successfully',
            'data' => [
                'id' => (int) $id,
            ],
        ], 200);
    }

    public function alertsDestroy(Request $request, $id)
    {
        $validator = Validator::make(['id' => $id], [
            'id' => 'required|integer|min:1',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Alert deleted successfully',
            'data' => [
                'id' => (int) $id,
            ],
        ], 200);
    }

    public function userRelationshipManager(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Relationship Manager details successfully extracted.',
            'data' => [
                'manager_name' => 'Pankaj Thakur',
                'photo' => 'https://example.com/photos/pankaj_thakur.jpg',
                'phone' => '7000------',
                'manager_email' => 'pankaj@bigmint.co',
                'designation' => 'Manager',
                'actions' => [
                    'call_link' => 'tel:+91XXXXXXXXXX',
                    'email_link' => 'mailto:pankaj@bigmint.co',
                ],
            ],
        ], 200);
    }

    public function userEntitlements(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'User entitlements fetched successfully',
            'data' => [
                'features' => (object) [],
                'limits' => (object) [],
            ],
        ], 200);
    }

    public function userAccountDelete(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Account deletion request processed successfully',
            'data' => [
                'otp_required' => true,
            ],
        ], 200);
    }

    public function helpVideoTutorials(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Video tutorial listing fetched successfully.',
            'items' => [
                [
                    'media_id' => 1,
                    'title' => 'Steel Price Forecast: Expert Panel Discussion',
                    'thumbnail_url' => 'https://example.com/thumb1.png',
                    'embed_link' => 'https://www.youtube.com/embed/dQw4w9WgXcQ',
                    'media_type_label' => 'LIVE',
                    'organizer' => 'Bigmint',
                    'views' => '1.2k',
                    'read_time' => '5 min read',
                ],
                [
                    'media_id' => 2,
                    'title' => 'Market pulse Weekly Ep. 42',
                    'thumbnail_url' => 'https://example.com/thumb2.png',
                    'embed_link' => 'https://www.youtube.com/embed/3tmd-ClpJxA',
                    'media_type_label' => 'PODCAST',
                    'organizer' => 'Bigmint',
                    'views' => '1.5k',
                    'read_time' => '1 min read',
                ],
            ],
        ], 200);
    }

    public function helpContact(Request $request)
    {
        return Response::json([
            'status' => true,
            'message' => 'Contact support details successfully extracted.',
            'data' => [
                [
                    'type' => 'WhatsApp Support',
                    'description' => 'Quick responses, 9 AM - 6 PM IST',
                    'value' => null,
                ],
                [
                    'type' => 'Phone Support',
                    'description' => null,
                    'value' => '+91 11 4556 7890',
                ],
                [
                    'type' => 'Email Support',
                    'description' => null,
                    'value' => 'support@bigmint.co',
                ],
            ],
        ], 200);
    }

    public function supportDiagnostics(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'platform' => 'sometimes|in:android,ios,web',
            'app_version' => 'sometimes|string|max:50',
            'device_model' => 'sometimes|string|max:100',
            'logs' => 'sometimes|array',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Diagnostics uploaded successfully',
            'data' => [
                'ticket_id' => 'SUP' . (string) (time() % 100000000),
                'received_at' => gmdate('c'),
            ],
        ], 201);
    }

    public function helpInviteFriends(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'invite_type' => 'required|in:email,whatsapp,sms',
            'recipient' => 'required|string|max:255',
            'message' => 'sometimes|string|max:500',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'Invite sent successfully',
            'data' => [
                'invite_type' => $request->input('invite_type'),
                'recipient' => $request->input('recipient'),
                'sent' => true,
                'sent_at' => gmdate('c'),
            ],
        ], 200);
    }

    public function aiTtsGenerate(Request $request, $articleId)
    {
        $validator = Validator::make(array_merge($request->all(), ['article_id' => $articleId]), [
            'article_id' => 'required|integer|min:1',
            'news_id' => 'required|integer|min:1',
            'description' => 'required|string|max:5000',
            'ai_config' => 'required|array',
        ]);

        if ($validator->fails()) {
            return $this->validationErrorResponse($validator);
        }

        return Response::json([
            'status' => true,
            'message' => 'AI voice synthesis complete.',
            'data' => [
                'news_id' => (int) $request->input('news_id'),
                'title' => 'Global iron ore exports show divergent trends',
                'description' => $request->input('description'),
                'audio_url' => 'https://api.bigmint.co/v1/media/ai-voice/BM-FERROUS-0324.mp3',
                'metadata' => [
                    'word_count' => 450,
                    'audio_duration' => '03:12',
                    'model_used' => 'Neural-Engine-v3',
                    'generation_time_ms' => 1240,
                ],
                'expires_at' => '2026-03-31T23:59:59Z',
            ],
        ], 200);
    }
}

