<?php

namespace App\Http\Requests\Campaign;

use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateCampaignRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null;
    }

    /**
     * @return array<string, ValidationRule|array<int, mixed>|string>
     */
    public function rules(): array
    {
        return [
            'judul' => ['required', 'string', 'max:255'],
            'url' => ['required', 'string', 'max:1000'],
            'jam_tayang_mulai' => ['required', 'date_format:H:i'],
            'jam_tayang_selesai' => ['required', 'date_format:H:i', 'after:jam_tayang_mulai'],
            'kategori_ids' => ['sometimes', 'array'],
            'kategori_ids.*' => [Rule::exists('kategoris', 'id')],
            'ad_type' => ['nullable', 'string', 'in:affiliate,link_website,backlink,press_release'],
            'ad_platform_id' => ['nullable', Rule::exists('ad_platforms', 'id')],
            'target_country' => ['nullable', 'string', 'max:5'],
            'budget_harian' => ['sometimes', 'required', 'integer', 'min:1'],
        ];
    }
}
