<?php

namespace Modules\Billing\Transformers;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class ServiceOfferingResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'service_code' => $this->service_code,
            'vat_price_type' => $this->vat_price_type,
            'service_type' => $this->service_type,
            'base_fee' => (float) $this->base_fee,
            'vat_type' => $this->vat_type,
            'vat_rate' => (float) $this->vat_rate,
            'selling_price' => (float) $this->selling_price,
            'subsidy_type' => $this->subsidy_type,
            'subsidy_value' => $this->subsidy_value,
            'status' => $this->status,
            'service_department' => $this->whenLoaded('serviceDepartment', function(){
                return $this->serviceDepartment;
            }),
            'sales_account' => $this->whenLoaded('salesAccount', function(){
                return $this->salesAccount;
            }),
        ];
    }
}
