<?php

namespace App\User\Database;

class QualityList
{
    public static $qualities = [
        "dvd-rip" => [
            "dvdrip",
            "dvdmux",
            "dvdr",
            "dvd-full",
            "full-rip",
            "iso rip",
            "lossless rip",
            "untouched rip",
            "dvd-5",
            "dvd-9",
        ],
        "hdtv, pdtv or dsrip" => [
            "dsr",
            "dsrip",
            "satrip",
            "dthrip",
            "dvbrip",
            "hdtv",
            "pdtv",
            "dtvrip",
            "tvrip",
            "hdtvrip",
        ],
        "vodrip" => [
            "vodrip",
            "vodr",
        ],
        "hc hd-rip" => [
            "hc",
            "hd-rip",
        ],
        "webcap" => [
            "web-cap",
            "webcap",
            "web cap",
        ],
        "hdrip" => [
            "hdrip",
            "web-dlrip",
        ],
        "webrip" => [
            "webrip",
            "web rip",
            "web-rip",
            "webrip (p2p)",
            "web rip (p2p)",
            "web-rip (p2p)",
        ],
        "web-dl" => [
            "webdl",
            "web dl",
            "web-dl",
            "web (scene)",
            "webrip",
        ],
        "blu-ray/bd/brrip" => [
            "blu-ray",
            "bluray",
            "bluray",
            "bdrip",
            "brip",
            "brrip",
            "bdr[13]",
            "bd25",
            "bd50",
            "bd66",
            "bd100",
            "bd5",
            "bd9",
            "bdmv",
            "bdiso",
            "complete.bluray",
        ],
        "4k" => [
            "cbr",
            "vbr",
        ],
    ];

    public static function getQualities(): array
    {
        return self::$qualities;
    }

    public static function getBaseQualities(): array
    {
        return array_keys(self::$qualities);
    }

    public static function getBaseQualityFromSubQuality(string $key): ?string
    {
        return array_search($key, self::$qualities) ?? null;
    }

    public static function asSelectOptions(): array
    {
        $result = ['n/a' => null, '-' => '-'];
        foreach (array_keys(static::$qualities) as $quality) {
            $result[$quality] = $quality;
        }
        return $result;
    }

    public static function getAsReverseMap(): array
    {
        $results = [];

        foreach (self::$qualities as $baseQualtiy => $subQualities) {
            foreach ($subQualities as $subQuality) {
                $results[$subQuality] = $baseQualtiy;
            }
        }

        return $results;
    }
}
