/**
 * @license
 * Copyright 2017 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {ICommand} from "../base";
import {Oas20License, Oas30License, OasDocument, OasLicense, OasNode} from "oai-ts-core";
import {DeleteNodeCommand} from "./delete-node.command";


/**
 * Factory function.
 */
export function createDeleteLicenseCommand(document: OasDocument): DeleteNodeCommand<Oas20License> | DeleteNodeCommand<Oas30License> {
    let property: string = "license";
    let parent: OasNode = document.info;
    if (document.getSpecVersion() === "2.0") {
        return new DeleteLicenseCommand_20(property, parent);
    } else {
        return new DeleteLicenseCommand_30(property, parent);
    }
}


/**
 * A command used to delete the license.
 */
export abstract class AbstractDeleteLicenseCommand<T extends OasLicense> extends DeleteNodeCommand<T> implements ICommand {

    /**
     * Unmarshalls a node into the appropriate type.
     * @param {OasDocument} doc
     * @param node
     * @return {T}
     */
    protected readNode(doc: OasDocument, node: any): T {
        let license: T = doc.info.createLicense() as T;
        this.oasLibrary().readNode(node, license);
        return license;
    }

}


/**
 * OAI 2.0 impl.
 */
export class DeleteLicenseCommand_20 extends AbstractDeleteLicenseCommand<Oas20License> {

    protected type(): string {
        return "DeleteLicenseCommand_20";
    }

}


/**
 * OAI 3.0 impl.
 */
export class DeleteLicenseCommand_30 extends AbstractDeleteLicenseCommand<Oas30License> {

    protected 
(): string {
        return "DeleteLicenseCommand_30";
    }

}

type