<?php

declare(strict_types=1);

namespace MauticPlugin\DealFlowBundle\Form\Type;

use MauticPlugin\DealFlowBundle\Service\AutomationOptionsProvider;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;

final class CampaignDealMatchConditionType extends AbstractType
{
    public function __construct(
        private readonly AutomationOptionsProvider $optionsProvider,
    ) {
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('pipeline_id', ChoiceType::class, [
                'label' => 'Deal pipeline',
                'choices' => $this->optionsProvider->getPipelineChoices(),
                'required' => false,
                'placeholder' => 'Any pipeline',
                'choice_translation_domain' => false,
                'attr' => ['class' => 'form-control'],
            ])
            ->add('stage_id', ChoiceType::class, [
                'label' => 'Deal stage',
                'choices' => $this->optionsProvider->getGroupedStageChoices(),
                'required' => false,
                'placeholder' => 'Any stage',
                'choice_translation_domain' => false,
                'attr' => ['class' => 'form-control'],
            ])
            ->add('status', ChoiceType::class, [
                'label' => 'Deal status',
                'choices' => $this->optionsProvider->getStatusChoices(true),
                'required' => false,
                'choice_translation_domain' => false,
                'attr' => ['class' => 'form-control'],
            ])
            ->add('stakeholder_role', ChoiceType::class, [
                'label' => 'Stakeholder role',
                'choices' => $this->optionsProvider->getStakeholderRoleChoices(true),
                'required' => false,
                'choice_translation_domain' => false,
                'attr' => ['class' => 'form-control'],
            ])
            ->add('min_amount', NumberType::class, [
                'label' => 'Minimum deal amount',
                'required' => false,
                'scale' => 2,
                'attr' => [
                    'class' => 'form-control',
                    'step' => '0.01',
                ],
            ])
            ->add('max_amount', NumberType::class, [
                'label' => 'Maximum deal amount',
                'required' => false,
                'scale' => 2,
                'attr' => [
                    'class' => 'form-control',
                    'step' => '0.01',
                ],
            ]);
    }

    public function getBlockPrefix(): string
    {
        return 'dealflow_campaign_match_condition';
    }
}
