package com.atlassian.bitbucket.internal.defaultreviewers.rest;

import com.atlassian.bitbucket.repository.ref.restriction.RefMatcherType;
import com.atlassian.bitbucket.rest.RestMapEntity;

import javax.annotation.Nullable;
import java.util.Map;

public class RestRefMatcherType extends RestMapEntity {

    private final String ID = "id";
    private final String NAME = "name";

    private RestRefMatcherType(String id, String name) {
        put(ID, id);
        put(NAME, name);
    }

    private RestRefMatcherType(Map<String, Object> values) {
        super(values);
    }

    public RestRefMatcherType() {

    }

    public RestRefMatcherType(RefMatcherType type) {
        this(type.getId(), type.getDisplayId());
    }

    public String getId() {
        return getStringProperty(ID);
    }

    public String getName() {
        return getStringProperty(NAME);
    }

    @Nullable
    @SuppressWarnings("unchecked")
    public static RestRefMatcherType valueOf(@Nullable Object object) {
        if (object instanceof RestRefMatcherType) {
            return (RestRefMatcherType) object;
        }
        if (object instanceof Map) {
            return new RestRefMatcherType((Map<String, Object>) object);
        }
        return null;
    }
}
