<?php
namespace App\Http\Controllers\Api\V1;use App\Http\Controllers\Controller;use App\Models\Corridor;use App\Http\Resources\CorridorResource;use App\Models\Country;use App\Models\Currency;use Illuminate\Http\Request;use Illuminate\Support\Facades\Cache;
class ConfigController extends Controller {public function bootstrap(Request $r){$data=Cache::remember('config.bootstrap.'.$r->user()->merchant_id,300,function()use($r){$corr=Corridor::with('fromCountry','toCountry')->where('is_active',true);if($r->user()->merchant)$corr->where('from_country_id',$r->user()->merchant->country_id);return ['currencies'=>Currency::where('is_active',true)->get(),'corridors'=>$corr->get()->map(fn($c)=>(new CorridorResource($c))->resolve($r))->all(),'code_validity_default_hours'=>config('payment.default_code_validity_hours'),'money_shape'=>['minor'=>2550000,'currency'=>'PKR','decimals'=>2,'formatted'=>'PKR 25,500.00']];});return ['data'=>$data];}public function countries(){return ['data'=>Country::with('currency')->where('is_active',true)->get()];}public function currencies(){return ['data'=>Currency::where('is_active',true)->get()];}public function corridors(Request $r){$q=Corridor::with('fromCountry','toCountry')->where('is_active',true);if($r->user()->merchant)$q->where('from_country_id',$r->user()->merchant->country_id);return CorridorResource::collection($q->get());}}
