﻿using Eflat.Util;

namespace Eflat
{
    internal sealed class IfStatement : Statement
    {
        /// <summary>
        /// The location of the if statement.
        /// </summary>
        private readonly StreamLocation StreamLocation;

        /// <summary>
        /// The condition that decides which path we take (IfTrue, or IfFalse).
        /// </summary>
        public readonly Expression Condition;

        /// <summary>
        /// The statement(s) to be executed if Condition evaluates to true.
        /// </summary>
        public readonly ScopedStatement IfTrue;

        /// <summary>
        /// The statement(s) to be executed if Condition evaluates to false.
        /// </summary>
        public readonly Option<ScopedStatement> IfFalse;

        public IfStatement(IHasLocation hasLocation, Expression condition, ScopedStatement ifTrue, Option<ScopedStatement> ifFalse = new Option<ScopedStatement>())
        {
            StreamLocation = hasLocation.Location;
            Condition = condition;
            IfTrue = ifTrue;
            IfFalse = ifFalse;
        }

        /// <summary>
        /// The location of the if statement.
        /// </summary>
        public override StreamLocation Location => StreamLocation;

        /// <summary>
        /// An if statement does not require a semicolon.
        /// </summary>
        public override bool RequiresSemicolon => false;
    }
}