<?php

namespace Opentalent\OtCore\Tests\Unit\Domain;

use AssertionError;
use Nimut\TestingFramework\TestCase\UnitTestCase;
use Opentalent\OtCore\Domain\Model\Donor;
use Opentalent\OtCore\Domain\Model\Organization;

class OrganizationTest extends UnitTestCase
{
    /**
     * Object should instantiate correctly, and properties
     * set with setters should be retrieved by getters
     *
     * @test
     */
    public function instantiation() {
        $organization = new Organization();

        $organization->setId(1);
        $organization->setType("PortailOrganization");
        $organization->setSubDomain('subdomain');
        $organization->setName('name');
        $organization->setSlug('slug');
        $organization->setPrincipalType('type');
        $organization->setDescription('description');
        $organization->setCategories(['category']);
        $organization->setAddressCity('city');
        $organization->setPostalCode('00000');
        $organization->setStreetAddress('street');
        $organization->setLatitude(1.2345);
        $organization->setLongitude(1.2345);
        $organization->setCountry('country');
        $organization->setLogo('logo.svg');
        $organization->setParentId(2);
        $organization->setParentName('parent');
        $organization->setParentSubdomain('parent subdomain');

        $this->assertEquals(1, $organization->getId());
        $this->assertEquals("PortailOrganization", $organization->getType());
        $this->assertEquals('subdomain', $organization->getSubDomain());
        $this->assertEquals('name', $organization->getName());
        $this->assertEquals('slug', $organization->getSlug());
        $this->assertEquals('type', $organization->getPrincipalType());
        $this->assertEquals('description', $organization->getDescription());
        $this->assertEquals(['category'], $organization->getCategories());
        $this->assertEquals('city', $organization->getAddressCity());
        $this->assertEquals('00000', $organization->getPostalCode());
        $this->assertEquals('street', $organization->getStreetAddress());
        $this->assertEquals(1.2345, $organization->getLatitude());
        $this->assertEquals(1.2345, $organization->getLongitude());
        $this->assertEquals('country', $organization->getCountry());
        $this->assertEquals('logo.svg', $organization->getLogo());
        $this->assertEquals(2, $organization->getParentId());
        $this->assertEquals('parent', $organization->getParentName());
        $this->assertEquals('parent subdomain', $organization->getParentSubdomain());
    }

    /**
     * Nullable fields should be able to be set to null,
     * while non nullable shall raise an exception if set to null
     *
     * @test
     */
    public function nullableOrNot() {

        $organization = new Organization();

        // non-nullable properties
        try {
            $organization->setId(null);
            throw new AssertionError('Organization::setId should not accept a null value');
        } catch (\TypeError $e) {}

        // nullable properties
        $organization->setType(null);
        $organization->setSubDomain(null);
        $organization->setName(null);
        $organization->setSlug(null);
        $organization->setPrincipalType(null);
        $organization->setDescription(null);
        $organization->setCategories(null);
        $organization->setAddressCity(null);
        $organization->setPostalCode(null);
        $organization->setStreetAddress(null);
        $organization->setLatitude(null);
        $organization->setLongitude(null);
        $organization->setCountry(null);
        $organization->setLogo(null);
        $organization->setParentId(null);
        $organization->setParentName(null);
        $organization->setParentSubdomain(null);

        // Just to avoid this test to be considered as risky
        $this->assertEquals(1, 1);
    }


}
