import { EntityPathStyle } from "./entity/EntityPathStyle.js";
import { PathDisplayType } from "./PathDisplayType.js";
import { assert } from "../../../../core/assert.js";
import { RibbonPathStyle } from "./ribbon/RibbonPathStyle.js";
import { TubePathStyle } from "./tube/TubePathStyle.js";

export class PathDisplaySpec {
    constructor() {
        /**
         *
         * @type {PathDisplayType|string}
         */
        this.type = PathDisplayType.None;

        /**
         *
         * @type {EntityPathStyle|RibbonPathStyle|TubePathStyle|null}
         */
        this.style = null;
    }

    /**
     *
     * @param {PathDisplayType} type
     * @param {EntityPathStyle|RibbonPathStyle|TubePathStyle} style
     */
    static from(type, style) {
        const r = new PathDisplaySpec();

        r.type = type;
        r.style = style;

        return r;
    }

    fromJSON({ type, style }) {
        assert.enum(type, PathDisplayType, "type");

        this.type = type;

        switch (type) {
            case PathDisplayType.Tube:
                this.style = new TubePathStyle();
                break;
            case PathDisplayType.Ribbon:
                this.style = new RibbonPathStyle();
                break;
            case PathDisplayType.Entity:
                this.style = new EntityPathStyle();
                break;
            case PathDisplayType.None:
                this.style = null;
                break;
            default:
                throw new Error(`Unsupported type '${type}'`);
        }

        if (this.style !== null) {
            this.style.fromJSON(style);
        }
    }

    static fromJSON(j) {
        const r = new PathDisplaySpec();

        r.fromJSON(j);

        return r;
    }
}
