<?php

namespace App\Tests\Patient;

use App\Auth\Entity\User;
use App\UserProfile\Entity\UserProfile;
use PHPUnit\Framework\TestCase;

/**
 * Unit coverage for the patient demographic columns added to UserProfile
 * (field_of_study, province_id, city_id, postal_code, referral_source):
 * setters round-trip through the getters and toArray() exposes the API keys.
 */
class UserProfileDemographicsTest extends TestCase
{
    private function profile(): UserProfile
    {
        return new UserProfile(new User('09121234567'));
    }

    public function testNewDemographicSettersRoundTrip(): void
    {
        $p = $this->profile();
        $p->setFieldOfStudy('نرم‌افزار')
            ->setProvinceId(8)
            ->setCityId(42)
            ->setPostalCode('8913746351')
            ->setReferralSource('اینستاگرام');

        self::assertSame('نرم‌افزار', $p->getFieldOfStudy());
        self::assertSame(8, $p->getProvinceId());
        self::assertSame(42, $p->getCityId());
        self::assertSame('8913746351', $p->getPostalCode());
        self::assertSame('اینستاگرام', $p->getReferralSource());
    }

    public function testNewFieldsDefaultToNull(): void
    {
        $p = $this->profile();

        self::assertNull($p->getFieldOfStudy());
        self::assertNull($p->getProvinceId());
        self::assertNull($p->getCityId());
        self::assertNull($p->getPostalCode());
        self::assertNull($p->getReferralSource());
    }

    public function testToArrayExposesNewKeys(): void
    {
        $arr = $this->profile()
            ->setFieldOfStudy('پزشکی')
            ->setProvinceId(1)
            ->setCityId(2)
            ->setPostalCode('1234567890')
            ->setReferralSource('معرفی دوستان')
            ->toArray();

        self::assertSame('پزشکی', $arr['field_of_study']);
        self::assertSame(1, $arr['province_id']);
        self::assertSame(2, $arr['city_id']);
        self::assertSame('1234567890', $arr['postal_code']);
        self::assertSame('معرفی دوستان', $arr['referral_source']);
    }
}
