<?php

namespace App\Domains\Sale\Resources\AdminApp;

use App\Domains\Purchase\Models\Purchase;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/** @mixin Purchase */
class SaleResource extends JsonResource
{
    /** @return array<string, mixed> */
    public function toArray(Request $request): array
    {
        $ticketsCount = (int) ($this->tickets_count ?? 0);

        return [
            'id' => $this->id,
            'created_at' => $this->created_at,
            'customer_name' => $this->nombre_apellido,
            'quantity' => (int) ($this->quantity ?? 0),
            'status' => $this->status,
            'total' => number_format((float) $this->total, 2, '.', ''),
            'tickets_count' => $ticketsCount,
            'has_generated_tickets' => $ticketsCount > 0,
        ];
    }
}
