<?php

namespace App\Helpers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Conner\Tagging\Model\Tag;

class FilterCategories
{
    public static function getFilterCategories()
    {
        $taglist = Cache::remember(
            'searchtags',
            300,
            fn () => Tag::where('count', '>', 0)
                ->orderBy('slug')
                ->get(),
        );

        $appearances = [
            'Loli',
            'Shota',
            'Milf',
            'Futanari',
            'Big Boobs',
            'Small Boobs',
            'Dark Skin',
            'Cosplay',
            'Elf',
            'Maid',
            'Nekomimi',
            'Nurse',
            'School Girl',
            'Succubus',
            'Teacher',
            'Trap',
            'Pregnant',
            'Glasses',
            'Swim Suit',
            'Ugly Bastard',
            'Monster',
        ];

        $types = [
            '3D',
            '4K',
            '48Fps',
            '4K 48Fps',
            'Censored',
            'Uncensored',
            'Comedy',
            'Fantasy',
            'Horror',
            'Vanilla',
            'Ntr',
            'Pov',
            'Filmed',
            'X-Ray',
        ];

        $actions = [
            'Anal',
            'Bdsm',
            'Facial',
            'Blow Job',
            'Boob Job',
            'Foot Job',
            'Hand Job',
            'Rimjob',
            'Inflation',
            'Masturbation',
            'Public Sex',
            'Rape',
            'Reverse Rape',
            'Threesome',
            'Orgy',
            'Gangbang',
        ];

        $excluded = [...$appearances, ...$types, ...$actions];

        $categories = [
            'Genres' => $taglist
                ->reject(fn ($tag) => in_array($tag->name, $excluded))
                ->pluck('name')
                ->toArray(),

            'Actions' => $actions,

            'Appearance' => collect($appearances)
                ->reject(function ($tag) {
                    return Auth::guest() && in_array($tag, ['Loli', 'Shota']);
                })
                ->toArray(),

            'Types' => $types,
        ];

        return $categories;
    }
}
