/*
 * Copyright (c) 2010-2026 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.openhab.binding.linkplay.internal.client.upnp;

import java.util.Locale;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
 *
 * @author Mark Herwege - Initial contribution
 * @author Dan Cunningham - Added to LinkPlay binding (from UPnP Control binding)
 */
@NonNullByDefault
public class UpnpEntryRes {

    private String protocolInfo;
    private @Nullable Long size;
    private String duration;
    private String importUri;
    private String res = "";

    public UpnpEntryRes(@Nullable String protocolInfo, @Nullable Long size, @Nullable String duration,
            @Nullable String importUri) {
        // According to the UPnP standard, res should always contain protocolInfo. Some devices do not respect this
        // standard in their AVTransport implementation. To avoid null pointer exceptions, take care of this special
        // case.
        this.protocolInfo = (protocolInfo == null) ? "*" : protocolInfo.trim();
        this.size = size;
        this.duration = (duration == null) ? "" : duration.trim();
        this.importUri = (importUri == null) ? "" : importUri.trim();
    }

    /**
     * @return the res
     */
    public String getRes() {
        return res;
    }

    /**
     * @param res the res to set
     */
    public void setRes(String res) {
        this.res = res.trim();
    }

    public String getProtocolInfo() {
        return protocolInfo;
    }

    /**
     * @return the size
     */
    public @Nullable Long getSize() {
        return size;
    }

    /**
     * @return the duration
     */
    public String getDuration() {
        return duration;
    }

    /**
     * @return the importUri
     */
    public String getImportUri() {
        return importUri;
    }

    /**
     * @return true if this resource defines a thumbnail as specified in the DLNA specs
     */
    public boolean isThumbnailRes() {
        return getProtocolInfo().toLowerCase(Locale.ROOT).contains("dlna.org_pn=jpeg_tn");
    }
}
