<?php

namespace App\Filament\Resources\Contracts\Pages;

use App\Filament\Resources\Contracts\ContractResource;
use App\Services\ContractScheduleService;
use Filament\Resources\Pages\CreateRecord;

class CreateContract extends CreateRecord
{
    protected static string $resource = ContractResource::class;

    protected function afterCreate(): void
    {
        $contract = $this->record;

        if ($contract->payment_template_id) {
            $template = $contract->paymentTemplate;
            if ($template) {
                ContractScheduleService::generateFromTemplate($contract, $template);
            }
        }
    }
}
