<?php

namespace App\Http\Requests\Concerns;

trait ValidatesMediaUploads
{
    /**
     * @return array<string, mixed>
     */
    protected function photoRules(string $prefix = 'photos', int $max = 1): array
    {
        return [
            $prefix => ['nullable', 'array', "max:{$max}"],
            "{$prefix}.*" => ['image', 'max:5120'],
            'remove_media_ids' => ['nullable', 'array'],
            'remove_media_ids.*' => ['integer'],
        ];
    }

    /**
     * @return array<string, mixed>
     */
    protected function variantImageRules(string $variantsKey = 'variants', int $max = 5): array
    {
        return [
            "{$variantsKey}.*.images" => ['nullable', 'array', "max:{$max}"],
            "{$variantsKey}.*.images.*" => ['image', 'max:5120'],
            "{$variantsKey}.*.remove_media_ids" => ['nullable', 'array'],
            "{$variantsKey}.*.remove_media_ids.*" => ['integer'],
        ];
    }

    /**
     * @return array<string, string>
     */
    protected function photoUploadAttributes(string $label): array
    {
        return [
            'photos' => $label,
            'photos.*' => $label,
            'remove_media_ids' => 'media yang dihapus',
            'remove_media_ids.*' => 'media yang dihapus',
        ];
    }

    /**
     * @return array<string, string>
     */
    protected function variantImageAttributes(string $variantsKey, string $label): array
    {
        return [
            "{$variantsKey}.*.images" => $label,
            "{$variantsKey}.*.images.*" => $label,
            "{$variantsKey}.*.remove_media_ids" => 'media yang dihapus',
            "{$variantsKey}.*.remove_media_ids.*" => 'media yang dihapus',
        ];
    }
}
