﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Stormancer.Management.Cmd
{
    class DeleteSceneInstanceCommand:Command
    {
        private string _id;
        public override string Name
        {
            get { return "delete scene"; }
        }

        public override async Task Run()
        {
            var app = Host.GetSelectedApp();
            var account = Host.GetSelectedAccount();
            if (app == null || account==null)
            {
                Console.WriteLine("Please select an application ('use app' command).");
                return;
            }

            using (var client = Host.CreateClient(app.Key))
            {
                

                var result = await client.DeleteAsync(account.AccountId + "/" + app.Name + "/scenes/" + _id);

                result.EnsureSuccessStatusCode();

                Console.WriteLine("Scene deleted.");
            }
        }

        public override void ParseParameters(Mono.Options.OptionSet p)
        {
            p.Add("id=", v => _id = v);
        }

        public override void Validate()
        {
            EnsureParameterExist(ref _id, "id");
        }
    }
}
