/** @module validate */
import { ValidationResultType } from './ValidationResultType';

/**
 * Result generated by schema validation
 */
export class ValidationResult {
    private _path: string;
    private _type: ValidationResultType;
    private _code: string;
    private _message: string;
    private _expected: any;
    private _actual: any;
 
    /**
     * Creates a new instance of validation ressult and sets its values.
     * 
     * @param path      a dot notation path of the validated element.
     * @param type      a type of the validation result: Information, Warning, or Error.
     * @param code      an error code.
     * @param message   a human readable message.
     * @param expected  an value expected by schema validation.
     * @param actual    an actual value found by schema validation.
     * 
     * @see [[ValidationResultType]]
     */
    public constructor(path: string = null, type: ValidationResultType = null, code: string = null, message: string = null, 
        expected: any = null, actual: any = null) {
        this._path = path;
        this._type = type;
        this._code = code;
        this._message = message;
        this._expected = expected;
        this._actual = actual;
    }

    /** 
     * Gets dot notation path of the validated element.
     * 
     * @returns the path of the validated element.
     */
    public getPath(): string {
        return this._path; 
    }

    /** 
     * Gets the type of the validation result: Information, Warning, or Error.
     * 
     * @returns the type of the validation result.
     * 
     * @see [[ValidationResultType]]
     */
    public getType(): ValidationResultType {
        return this._type; 
    }

    /**
     * Gets the error code.
     * 
     * @returns the error code
     */
    public getCode(): string {
        return this._code; 
    }

    /**
     * Gets the human readable message.
     * 
     * @returns the result message.
     */
    public getMessage(): string {
        return this._message; 
    }

    /**
     * Gets the value expected by schema validation.
     * 
     * @returns the expected value.
     */
    public getExpected(): any {
        return this._expected; 
    }

    /**
     * Gets the actual value found by schema validation.
     * 
     * @returns the actual value.
     */
    public getActual(): any {
        return this._actual; 
    }

    public toJSON(){
        return {
             path: this._path,
             type: this._type,
             code: this._code,
             message: this._message,
             expected: this._expected,
             actual: this._actual
        }
    }
}
