import MediaProfileRole from "./MediaProfileRole.js";
import MediaProfileSettings from "./MediaProfileSettings.js";
import MediaProfileViewSettings from "./MediaProfileViewSettings.js";

export default class MediaProfile{
    /**
     * @type {string}
     */
    name = "";

    /**
     * @type {string}
     */
    role = MediaProfileRole.ADMIN;

    /**
     * @type {MediaProfileSettings}
     */
    settings = new MediaProfileSettings();

    /**
     * @type {MediaProfileViewSettings}
     */
    playSettings = new MediaProfileViewSettings();

    /**
     * @param {object} jsonObj 
     * @returns {MediaProfile}
     */
    static fromJson(jsonObj) {
        const profile = new MediaProfile();

        if (jsonObj == null) {
            return profile;
        }

        if (jsonObj.name != null) {
            profile.name = jsonObj.name;
        }

        if (jsonObj.role != null) {
            profile.role = jsonObj.role;
        }

        if (jsonObj.settings != null && typeof jsonObj.settings === "object") {
            profile.settings = MediaProfileSettings.fromSettingsJson(jsonObj.settings);
        }

        if (jsonObj.playSettings != null && typeof jsonObj.playSettings === "object") {
            profile.playSettings = MediaProfileViewSettings.fromSettingsJson(jsonObj.playSettings);
        }

        return profile;
    }
}