using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace Photography.Scaledown
{
    public class VideoScaler
    {
        private IIOService io;

        public VideoScaler(IIOService io)
        {
            this.io = io;
        }

        public static async Task<int> Scale(IIOService io, Options opt, Item item)
        {
            return await new VideoScaler(io).Scale(opt, item);
        }

        public async Task<int> Scale(Options opt, Item item)
        {
            var logger = Program.CreateLogger<ImageScaler>();
            logger.LogInformation("Rescaling video: {0}", item.Relative);

            var args = String.Format("-i \"{0}\" -o \"{1}\" -e x264 -q 20 -X {2} -O -v0",
                item.Source,
                item.Target,
                opt.Width);

            return await ProcessExtensions.RunProcessAsync(opt.HandBrakeCli, args);
        }
    }
}