<?php

namespace App\Tests\Branch;

use App\Auth\Entity\User;
use App\Clinic\Entity\Clinic;
use App\Doctor\Entity\Doctor;
use App\Doctor\Entity\DoctorAddress;
use App\Tests\ApiTestCase;

/**
 * فیکسچرهای مشترک دامنهٔ شعبه. «شعبه» همان DoctorAddress است، پس هر تست به یک آدرس
 * از محیط جاری و یک آدرس از محیط بیگانه نیاز دارد تا مرز ۴۰۴ را واقعاً بسنجد.
 */
abstract class BranchTestCase extends ApiTestCase
{
    /** @return array{0: User, 1: Doctor, 2: DoctorAddress} */
    protected function doctorWithAddress(string $name = 'مطب مرکزی'): array
    {
        $user   = $this->createUser(['ROLE_USER', 'ROLE_DOCTOR']);
        $doctor = new Doctor($user, 'دکتر شعبه');
        $doctor->setMobileNumber($user->getMobileNumber());
        $this->em->persist($doctor);
        $this->em->flush();

        $address = DoctorAddress::forDoctor($doctor);
        $address->setName($name);
        $this->em->persist($address);
        $this->em->flush();

        return [$user, $doctor, $address];
    }

    /** @return array{0: User, 1: Clinic, 2: DoctorAddress} */
    protected function clinicWithAddress(string $name = 'شعبهٔ کلینیک'): array
    {
        $user   = $this->createUser(['ROLE_USER', 'ROLE_CLINIC']);
        $clinic = new Clinic($user);
        $clinic->setName('کلینیک تست شعبه');
        $this->em->persist($clinic);
        $this->em->flush();

        $address = DoctorAddress::forClinic($clinic->getId());
        $address->setName($name);
        $this->em->persist($address);
        $this->em->flush();

        return [$user, $clinic, $address];
    }
}
