<?PHP
/**
 * Represents a time indicator (CE / BCE).
 *
 * @author Joshua Ramon Enslin <joshua@museum-digital.de>
 */
declare(strict_types = 1);

/**
 * Represents a time indicator (CE / BCE).
 */
enum NodaCountingTimeIndicator implements JsonSerializable {

    case ce;
    case bce;

    /**
     * Returns a value of this type based on a string.
     *
     * @param string $input Input to get a value from.
     *
     * @return NodaCountingTimeIndicator
     */
    public static function fromString(string $input):NodaCountingTimeIndicator {

        return match($input) {
            '+' => self::ce,
            '-' => self::bce,
            'ce' => self::ce,
            'bce' => self::bce,
            default => throw new MDpageParameterNotFromListException("Unknown counting time indicator (bc / bce)"),
        };

    }

    /**
     * Returns a canonical string representation.
     *
     * @return string
     */
    public function toString():string {

        return match($this) {
            self::ce  => '+',
            self::bce => '-',
        };

    }

    /**
     * Returns a canonical string representation.
     *
     * @return string
     */
    public function toGerman():string {

        return match($this) {
            self::ce  => ' n. Chr.',
            self::bce => ' v. Chr.',
        };

    }

    /**
     * Provides the option to serialize as a string during json_encode().
     *
     * @return string
     */
    public function jsonSerialize():string {

        return $this->toString();

    }
}
