<?php

namespace App\Services\Elections;

use App\Models\Election;
use App\Services\Elections\Strategies\ApprovalStrategy;
use App\Services\Elections\Strategies\PluralityStrategy;
use App\Services\Elections\Strategies\RankedChoiceStrategy;
use App\Services\Elections\Strategies\ReferendumStrategy;
use App\Services\Elections\Strategies\WeightedStrategy;

class VotingStrategyFactory
{
    /**
     * Create a voting strategy instance from its name.
     */
    public function make(string $strategy): VotingStrategyInterface
    {
        return match ($strategy) {
            Election::STRATEGY_PLURALITY => new PluralityStrategy(),
            Election::STRATEGY_RANKED_CHOICE => new RankedChoiceStrategy(),
            Election::STRATEGY_APPROVAL => new ApprovalStrategy(),
            Election::STRATEGY_WEIGHTED => new WeightedStrategy(),
            Election::STRATEGY_REFERENDUM => new ReferendumStrategy(),
            default => throw new \InvalidArgumentException("Unknown voting strategy: {$strategy}"),
        };
    }
}
