<?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;
use Symfony\Component\Validator\Constraints\NotBlank;

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

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('target_stage_id', ChoiceType::class, [
                'label' => 'Target stage',
                'choices' => $this->optionsProvider->getGroupedStageChoices(),
                'required' => true,
                'choice_translation_domain' => false,
                'constraints' => [
                    new NotBlank(['message' => 'mautic.core.value.required']),
                ],
                'attr' => ['class' => 'form-control'],
            ])
            ->add('source_stage_id', ChoiceType::class, [
                'label' => 'Only move deals currently in stage',
                'choices' => $this->optionsProvider->getGroupedStageChoices(),
                'required' => false,
                'placeholder' => 'Any stage in the target pipeline',
                'choice_translation_domain' => false,
                'attr' => ['class' => 'form-control'],
            ])
            ->add('status', ChoiceType::class, [
                'label' => 'Deal status',
                'choices' => [
                    'Open' => 'open',
                    'Any status' => '',
                    'Closed won' => 'won',
                    'Closed lost' => 'lost',
                ],
                '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_stage_action';
    }
}
