using System;
using System.Collections.Generic;
using Top.Api.Response;
using Top.Api.Util;

namespace Top.Api.Request
{
    /// <summary>
    /// TOP API: taobao.product.img.upload
    /// </summary>
    public class ProductImgUploadRequest : BaseTopRequest<ProductImgUploadResponse>, ITopUploadRequest<ProductImgUploadResponse>
    {
        /// <summary>
        /// 产品图片ID.修改图片时需要传入
        /// </summary>
        public Nullable<long> Id { get; set; }

        /// <summary>
        /// 图片内容.图片最大为500K,只支持JPG,GIF格式.
        /// </summary>
        public FileItem Image { get; set; }

        /// <summary>
        /// 是否将该图片设为主图.可选值:true,false;默认值:false.
        /// </summary>
        public Nullable<bool> IsMajor { get; set; }

        /// <summary>
        /// 图片序号
        /// </summary>
        public Nullable<long> Position { get; set; }

        /// <summary>
        /// 产品ID.Product的id
        /// </summary>
        public Nullable<long> ProductId { get; set; }

        #region BaseTopRequest Members

        public override string GetApiName()
        {
            return "taobao.product.img.upload";
        }

        public override IDictionary<string, string> GetParameters()
        {
            TopDictionary parameters = new TopDictionary();
            parameters.Add("id", this.Id);
            parameters.Add("is_major", this.IsMajor);
            parameters.Add("position", this.Position);
            parameters.Add("product_id", this.ProductId);
            if (this.otherParams != null)
            {
                parameters.AddAll(this.otherParams);
            }
            return parameters;
        }

        public override void Validate()
        {
            RequestValidator.ValidateRequired("image", this.Image);
            RequestValidator.ValidateMaxLength("image", this.Image, 1048576);
            RequestValidator.ValidateRequired("product_id", this.ProductId);
        }

        #endregion

        #region ITopUploadRequest Members

        public IDictionary<string, FileItem> GetFileParameters()
        {
            IDictionary<string, FileItem> parameters = new Dictionary<string, FileItem>();
            parameters.Add("image", this.Image);
            return parameters;
        }

        #endregion
    }
}
