<?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', 'mimes:jpg,jpeg,png,webp', 'max:5120'],
            's3_keys' => ['nullable', 'array', "max:{$max}"],
            's3_keys.*' => ['required', 'string'],
            '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}.*.s3_keys" => ['nullable', 'array', "max:{$max}"],
            "{$variantsKey}.*.s3_keys.*" => ['required', 'string'],
            "{$variantsKey}.*.remove_media_ids" => ['nullable', 'array'],
            "{$variantsKey}.*.remove_media_ids.*" => ['integer'],
        ];
    }

    /**
     * @return array<string, string>
     */
    protected function photoUploadAttributes(string $label, string $prefix = 'photos'): array
    {
        return [
            $prefix => $label,
            "{$prefix}.*" => $label,
            's3_keys' => $label,
            's3_keys.*' => $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}.*.s3_keys" => $label,
            "{$variantsKey}.*.s3_keys.*" => $label,
            "{$variantsKey}.*.remove_media_ids" => 'media yang dihapus',
            "{$variantsKey}.*.remove_media_ids.*" => 'media yang dihapus',
        ];
    }
}
