<?php
namespace Database\Seeders;use App\Models\{Country,Corridor,Currency,ExchangeRate,Merchant,User};use Illuminate\Database\Seeder;use Spatie\Permission\Models\{Permission,Role};
class DatabaseSeeder extends Seeder {public function run():void{$perms=['merchant.view','merchant.create','merchant.update','merchant.suspend','user.view','user.create','user.update','user.suspend','transfer.create','transfer.view.own','transfer.view.all','payout.process','payout.view.own','payout.view.all','transfer.hold','transfer.release','transfer.cancel','rate.view','rate.update','corridor.view','corridor.update','settlement.view','settlement.run','settlement.mark','report.view','audit.view','config.update'];foreach($perms as $p)Permission::firstOrCreate(['name'=>$p,'guard_name'=>'web']);$admin=Role::firstOrCreate(['name'=>'admin','guard_name'=>'web']);$merchantRole=Role::firstOrCreate(['name'=>'merchant','guard_name'=>'web']);$staff=Role::firstOrCreate(['name'=>'merchant_user','guard_name'=>'web']);$admin->syncPermissions($perms);$merchantRole->syncPermissions(['user.view','user.create','user.update','user.suspend','transfer.create','transfer.view.own','payout.process','payout.view.own']);$staff->syncPermissions(['transfer.create','transfer.view.own','payout.process','payout.view.own']);Currency::upsert([['code'=>'PKR','name'=>'Pakistani Rupee','symbol'=>'Rs','decimals'=>2,'is_active'=>true,'created_at'=>now(),'updated_at'=>now()],['code'=>'IDR','name'=>'Indonesian Rupiah','symbol'=>'Rp','decimals'=>0,'is_active'=>true,'created_at'=>now(),'updated_at'=>now()]],['code']);$pk=Country::updateOrCreate(['iso2'=>'PK'],['iso3'=>'PAK','name'=>'Pakistan','dial_code'=>'+92','currency_code'=>'PKR','is_active'=>true]);$id=Country::updateOrCreate(['iso2'=>'ID'],['iso3'=>'IDN','name'=>'Indonesia','dial_code'=>'+62','currency_code'=>'IDR','is_active'=>true]);$corr=Corridor::updateOrCreate(['from_country_id'=>$pk->id,'to_country_id'=>$id->id],['min_amount_minor'=>500000,'max_amount_minor'=>50000000,'daily_cap_minor'=>200000000,'code_validity_hours'=>72,'is_active'=>true]);$adminUser=User::firstOrCreate(['email'=>'admin@example.com'],['name'=>'Platform Admin','phone'=>'+923001111111','password'=>'ChangeMe!12345','can_send'=>false,'can_receive'=>false]);$adminUser->syncRoles(['admin']);$pkm=Merchant::firstOrCreate(['code'=>'MRC-PK-0001'],['name'=>'Demo Pakistan Agent','country_id'=>$pk->id,'currency_code'=>'PKR','contact_name'=>'Pakistan Agent','contact_phone'=>'+923001111112','contact_email'=>'pk-agent@example.com','can_send'=>true,'can_receive'=>false,'per_txn_min_minor'=>500000,'per_txn_max_minor'=>50000000,'daily_limit_minor'=>200000000]);$idm=Merchant::firstOrCreate(['code'=>'MRC-ID-0001'],['name'=>'Demo Indonesia Agent','country_id'=>$id->id,'currency_code'=>'IDR','contact_name'=>'Indonesia Agent','contact_phone'=>'+628111111111','contact_email'=>'id-agent@example.com','can_send'=>false,'can_receive'=>true,'per_txn_min_minor'=>0,'per_txn_max_minor'=>1000000000,'daily_limit_minor'=>5000000000]);$send=User::firstOrCreate(['email'=>'send@example.com'],['merchant_id'=>$pkm->id,'name'=>'Send Agent','phone'=>'+923001111113','password'=>'ChangeMe!12345','can_send'=>true,'can_receive'=>false]);$send->syncRoles(['merchant']);$recv=User::firstOrCreate(['email'=>'receive@example.com'],['merchant_id'=>$idm->id,'name'=>'Receive Agent','phone'=>'+628111111112','password'=>'ChangeMe!12345','can_send'=>false,'can_receive'=>true]);$recv->syncRoles(['merchant']);ExchangeRate::firstOrCreate(['from_currency'=>'PKR','to_currency'=>'IDR','effective_from'=>now()->startOfMinute()],['rate'=>'57.00000000','margin_percent'=>'1.000','fee_flat_minor'=>50000,'fee_percent'=>'1.000','created_by'=>$adminUser->id,'created_at'=>now()]);}}
