<?php

namespace OSM\Element\Member;

class Member {

    public int $ref;
    public string $role;

    public static function createFromArray($array) {
        assert(is_array($array));

        $hasType = isset($array['type']);
        assert($hasType);

        $className = __NAMESPACE__.'\\'.ucfirst($array['type']);
        $hasClass = class_exists($className);

        $instance = new $className();

        $hasRef = isset($array['ref']);
        assert($hasRef);
        $instance->ref = (int) $array['ref'];

        $hasRole = isset($array['role']);
        assert($hasRole);
        $instance->role = (string) $array['role'];

        $instance->completeFromArray($array);

        return $instance;
    }
    
    public function isSame(Member $other): bool {
        return ($this->ref === $other->ref);
    }

}