<?php

namespace Database\Seeders;

use App\Models\Business;
use App\Models\NotificationTemplate;
use Illuminate\Database\Seeder;

class NotificationTemplateSeeder extends Seeder
{
    public function run(): void
    {
        $business=Business::firstOrCreate(['id'=>1],['name'=>'Microfinance']);
        $templates=[
            'pre_due'=>[
                'subject'=>'Upcoming loan payment - {loan_number}',
                'body'=>'Dear {customer_name}, installment #{installment_number} for loan {loan_number} has {amount_due} remaining and is due on {due_date}. Please pay on time. — {business_name}',
            ],
            'due'=>[
                'subject'=>'Loan payment due today - {loan_number}',
                'body'=>'Dear {customer_name}, installment #{installment_number} for loan {loan_number} has {amount_due} remaining and is due today ({due_date}). Please make payment today. — {business_name}',
            ],
            'overdue'=>[
                'subject'=>'Overdue loan payment - {loan_number}',
                'body'=>'Dear {customer_name}, installment #{installment_number} for loan {loan_number} has {amount_due} remaining and is overdue by {days_overdue} day(s). Please make payment promptly. — {business_name}',
            ],
        ];

        foreach($templates as $event=>$copy){
            foreach(NotificationTemplate::CHANNELS as $channel){
                NotificationTemplate::firstOrCreate(
                    ['business_id'=>$business->id,'event_type'=>$event,'channel'=>$channel],
                    ['subject'=>$channel==='email' ? $copy['subject'] : null,'body'=>$copy['body'],'active'=>true]
                );
            }
        }
    }
}
