<?php

namespace App\Http\Resources\Promo;

use App\Http\Resources\BaseResource;
use Illuminate\Http\Request;

final class PromoResource extends BaseResource
{
    /**
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'code' => $this->code,
            'name' => $this->name,
            'discount_type' => $this->discount_type,
            'discount_value' => (float) $this->discount_value,
            'discount_amount' => $this->when(isset($this->discount_amount), $this->discount_amount),
            'bonus_gold' => $this->when(isset($this->bonus_gold), $this->bonus_gold),
            'is_auto' => $this->when(isset($this->is_auto), $this->is_auto),
            'usage_count' => $this->when(isset($this->usage_count), $this->usage_count),
            'usage_limit' => $this->when(isset($this->usage_limit), $this->usage_limit),
            'remaining_slots' => $this->when(isset($this->remaining_slots), $this->remaining_slots),
        ];
    }
}
