namespace Lada.Framework.DTO.Models.Media
{
    /// <summary>
    /// Thông tin chi tiết của video
    /// </summary>
    public class VideoInfo
    {
        /// <summary>
        /// Thời lượng video (giây)
        /// </summary>
        public int Duration { get; set; }

        /// <summary>
        /// Chiều rộng video (pixel)
        /// </summary>
        public int Width { get; set; }

        /// <summary>
        /// Chiều cao video (pixel)
        /// </summary>
        public int Height { get; set; }

        /// <summary>
        /// Frame rate (fps)
        /// </summary>
        public double FrameRate { get; set; }

        /// <summary>
        /// Bitrate video (kbps)
        /// </summary>
        public int Bitrate { get; set; }

        /// <summary>
        /// Codec video
        /// </summary>
        public string Codec { get; set; } = string.Empty;

        /// <summary>
        /// Format container
        /// </summary>
        public string Format { get; set; } = string.Empty;

        /// <summary>
        /// Kích thước file (bytes)
        /// </summary>
        public long FileSize { get; set; }

        /// <summary>
        /// Có audio track không
        /// </summary>
        public bool HasAudio { get; set; }

        /// <summary>
        /// Audio codec
        /// </summary>
        public string AudioCodec { get; set; } = string.Empty;

        /// <summary>
        /// Audio bitrate (kbps)
        /// </summary>
        public int AudioBitrate { get; set; }

        /// <summary>
        /// Lỗi nếu có (khi parse thông tin)
        /// </summary>
        public string? Error { get; set; }

        /// <summary>
        /// Có hợp lệ không
        /// </summary>
        public bool IsValid => string.IsNullOrEmpty(Error) && Duration > 0 && Width > 0 && Height > 0;

        /// <summary>
        /// Độ phân giải dạng string (VD: "1920x1080")
        /// </summary>
        public string Resolution => $"{Width}x{Height}";

        /// <summary>
        /// Thời lượng dạng string (VD: "00:05:30")
        /// </summary>
        public string DurationString
        {
            get
            {
                var timeSpan = TimeSpan.FromSeconds(Duration);
                return timeSpan.ToString(@"hh\:mm\:ss");
            }
        }

        /// <summary>
        /// Kích thước file dạng string (VD: "15.2 MB")
        /// </summary>
        public string FileSizeString
        {
            get
            {
                if (FileSize < 1024)
                    return $"{FileSize} B";
                else if (FileSize < 1024 * 1024)
                    return $"{FileSize / 1024.0:F1} KB";
                else if (FileSize < 1024 * 1024 * 1024)
                    return $"{FileSize / (1024.0 * 1024.0):F1} MB";
                else
                    return $"{FileSize / (1024.0 * 1024.0 * 1024.0):F1} GB";
            }
        }
    }
}
