<?php

declare(strict_types=1);

namespace App\Http\Resources;

use App\Models\Profile;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * The owner's view of their own profile. Includes contact and billing details,
 * so it must not be used on any public endpoint.
 *
 * @mixin Profile
 */
class ProfileResource extends JsonResource
{
    /** @return array<string, mixed> */
    public function toArray(Request $request): array
    {
        return [
            'display_name' => $this->display_name,
            'avatar_url' => $this->avatar_path
                ? route('api.v1.media.show', ['path' => $this->avatar_path])
                : null,
            'bio' => $this->bio,
            'country_code' => $this->country_code,
            'city' => $this->city,
            'address_line1' => $this->address_line1,
            'address_line2' => $this->address_line2,
            'postal_code' => $this->postal_code,
            'website_url' => $this->website_url,
            'company_name' => $this->company_name,
            'whatsapp_number' => $this->whatsapp_number,
            'marketing_opt_in' => (bool) $this->marketing_opt_in,
            'notification_preferences' => $this->preferences(),
        ];
    }
}
