<?php

namespace App\Domain\Payroll\Enums;

/** How a component's amount is arrived at (§52). */
enum CalculationMode: string
{
    case Fixed = 'fixed';
    case PercentOfBasic = 'percent_of_basic';
    case PercentOfGross = 'percent_of_gross';
    case Attendance = 'attendance';
    case Overtime = 'overtime';

    public function label(): string
    {
        return match ($this) {
            self::Fixed => 'Fixed amount',
            self::PercentOfBasic => 'Percentage of basic',
            self::PercentOfGross => 'Percentage of gross',
            self::Attendance => 'Per day absent',
            self::Overtime => 'Per overtime hour',
        };
    }

    public function needsRate(): bool
    {
        return in_array($this, [self::PercentOfBasic, self::PercentOfGross], true);
    }

    /**
     * Percentage-of-gross has to wait until the earnings are known, so it is
     * calculated in a second pass.
     */
    public function dependsOnGross(): bool
    {
        return $this === self::PercentOfGross;
    }

    /** @return array<int, string> */
    public static function values(): array
    {
        return array_column(self::cases(), 'value');
    }
}
