using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Электронная_Фармация.Classes
{
    public sealed class BuyerDto
    {
        [JsonPropertyName("buyer_id")]
        public string BuyerId { get; set; }

        [JsonPropertyName("id")]
        public string Id { get; set; }

        [JsonPropertyName("username")]
        public string Username { get; set; }

        [JsonPropertyName("login")]
        public string Login { get; set; }

        [JsonPropertyName("name")]
        public string Name { get; set; }

        public string ResolvedId =>
            !string.IsNullOrWhiteSpace(BuyerId) ? BuyerId.Trim() :
            !string.IsNullOrWhiteSpace(Id) ? Id.Trim() :
            string.Empty;
    }

    public sealed class BuyersResponse
    {
        [JsonPropertyName("buyers")]
        public List<BuyerDto> Buyers { get; set; }

        [JsonPropertyName("items")]
        public List<BuyerDto> Items { get; set; }
    }

    public sealed class BuyerPriceListAssignmentDto
    {
        [JsonPropertyName("price_list_id")]
        public string PriceListId { get; set; }

        [JsonPropertyName("name")]
        public string Name { get; set; }

        [JsonPropertyName("supplier_id")]
        public string SupplierId { get; set; }

        [JsonPropertyName("supplier_name")]
        public string SupplierName { get; set; }

        /// <summary>Клиентская скидка на этот прайс.</summary>
        [JsonPropertyName("markup_pct")]
        public decimal? MarkupPct { get; set; }

        /// <summary>Базовая скидка самого прайса.</summary>
        [JsonPropertyName("default_markup_pct")]
        public decimal? DefaultMarkupPct { get; set; }
    }

    public sealed class BuyerPriceListsResponse
    {
        [JsonPropertyName("items")]
        public List<BuyerPriceListAssignmentDto> Items { get; set; }

        [JsonPropertyName("price_lists")]
        public List<BuyerPriceListAssignmentDto> PriceLists { get; set; }
    }

    public sealed class PriceListDto
    {
        [JsonPropertyName("price_list_id")]
        public string PriceListId { get; set; }

        [JsonPropertyName("id")]
        public string Id { get; set; }

        [JsonPropertyName("name")]
        public string Name { get; set; }

        [JsonPropertyName("supplier_id")]
        public string SupplierId { get; set; }

        [JsonPropertyName("supplier_name")]
        public string SupplierName { get; set; }

        [JsonPropertyName("default_markup_pct")]
        public decimal? DefaultMarkupPct { get; set; }

        public string ResolvedId =>
            !string.IsNullOrWhiteSpace(PriceListId) ? PriceListId.Trim() :
            !string.IsNullOrWhiteSpace(Id) ? Id.Trim() :
            string.Empty;
    }

    public sealed class PriceListsResponse
    {
        [JsonPropertyName("price_lists")]
        public List<PriceListDto> PriceLists { get; set; }

        [JsonPropertyName("items")]
        public List<PriceListDto> Items { get; set; }
    }

    public sealed class PriceListRegionDto
    {
        [JsonPropertyName("region_id")]
        public string RegionId { get; set; }

        [JsonPropertyName("region_name")]
        public string RegionName { get; set; }

        [JsonPropertyName("in_work")]
        public bool? InWork { get; set; }

        [JsonPropertyName("markup_pct")]
        public decimal? MarkupPct { get; set; }

        [JsonPropertyName("base_price_type")]
        public string BasePriceType { get; set; }
    }

    /// <summary>
    /// Скидки, доступные для одной позиции прайса.
    /// Отсутствующий источник = 0.
    /// </summary>
    public sealed class ItemDiscountParts
    {
        public string PriceListId { get; set; }
        public decimal PriceListDiscountPct { get; set; }
        public decimal RegionDiscountPct { get; set; }
        public decimal ClientDiscountPct { get; set; }

        public decimal TotalDiscountPct =>
            PriceListDiscountPct + RegionDiscountPct + ClientDiscountPct;
    }
}
