<?php

namespace App\Http\Resources\Backoffice\Accounts;

use App\Helpers\Backoffice\MediaHelper;
use Illuminate\Http\Resources\Json\JsonResource;

class AccountResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */

    public function toArray($request)
    {
        $activeSubscription = $this->activeSubscriptions->first();
        $plan = $activeSubscription ? $activeSubscription->subscriptionPlan : null;

        return [
            'id' => $this->id,
            'company' => $this->company,
            'owner' => $this->owner ? $this->owner->email : '',
            'plan' => $plan ? $plan->name : '',
            'subscriptionStatus' => $activeSubscription ? $activeSubscription->status : 'No subscription',
            'isTrial' => $activeSubscription ? $activeSubscription->is_trial : '',
            'trialEndDate' => $activeSubscription ? $activeSubscription->trial_end_date : '',
            'endDate' => $activeSubscription ? $activeSubscription->end_date : '',
            'isExpired' => $activeSubscription ? $activeSubscription->is_expired : false,
            'cancelOn' => $activeSubscription ? $activeSubscription->cancel_on : null,
            'addressId' => $this->address_id,
            'billingAddressId' => $this->billing_address_id,
            'activeSubscriptionId' => $activeSubscription ? $activeSubscription->id : '',
        ];
    }
}
