using Sonex.DBWrapper;
using System;
using System.Threading.Tasks;

namespace Sonex.Client.Models;

public sealed class ProductModel
{
    public string Artnr { get; set; } = string.Empty;
    public string? ArticleName { get; set; }
    public string? SalesClass { get; set; }
    public string? InputGroup { get; set; }
    public DateTime? ArticleDimensionsChecked { get; set; }
    public DateTime? LastReceived { get; set; }
    public string? BestBeforeDateUsed { get; set; }
    public string? BestBeforeDateMix { get; set; }

    public decimal? PriceNl { get; set; }
    public decimal? PriceDe { get; set; }
    public decimal? PriceHc { get; set; }

    public string? PackagingSu { get; set; }
    public int? SuQuantity { get; set; }
    public decimal? SuWeightGross { get; set; }
    public decimal? SuWeightNet { get; set; }
    public decimal? SuLength { get; set; }
    public decimal? SuHeight { get; set; }
    public decimal? SuWidth { get; set; }
    public decimal? SuVolume { get; set; }
    public int? SuStackLimit { get; set; }
    public decimal? SuNestVolume { get; set; }
    public int? SuNestMax { get; set; }
    public string? SuStackability { get; set; }
    public string? SuFragile { get; set; }
    public string? SuKeepUpright { get; set; }

    public string? PackagingPu { get; set; }
    public int? PuQuantity { get; set; }
    public decimal? PuWeightGross { get; set; }
    public decimal? PuWeightNet { get; set; }
    public decimal? PuLength { get; set; }
    public decimal? PuHeight { get; set; }
    public decimal? PuWidth { get; set; }
    public decimal? PuVolume { get; set; }
    public int? PuStackLimit { get; set; }
    public decimal? PuNestVolume { get; set; }
    public int? PuNestMax { get; set; }
    public string? PuStackability { get; set; }
    public string? PuFragile { get; set; }
    public string? PuKeepUpright { get; set; }

    public string? PackagingHn { get; set; }
    public int? HnQuantity { get; set; }
    public decimal? HnWeightGross { get; set; }
    public decimal? HnWeightNet { get; set; }
    public decimal? HnLength { get; set; }
    public decimal? HnHeight { get; set; }
    public decimal? HnWidth { get; set; }
    public decimal? HnVolume { get; set; }
    public int? HnStackLimit { get; set; }
    public decimal? HnNestVolume { get; set; }
    public int? HnNestMax { get; set; }
    public string? HnStackability { get; set; }
    public string? HnFragile { get; set; }
    public string? HnKeepUpright { get; set; }

    public string? SuEans { get; set; }
    public string? PuEans { get; set; }
    public string? HnEans { get; set; }
    public string? ArticleParametersText { get; set; }
    public bool Archival { get; set; }
    //public string[] AllEans { get; set; } = [];
    public DateTime? LastEventDate { get; set; }
    //public string[] ArticleParameters { get; set; } = [];

    public static Task<DB.SingleResult<ProductModel>> Get(string artnr)
    {
        return DB.QuerySingleAsync<ProductModel>(
            "SELECT * FROM sonex.products WHERE artnr = @artnr LIMIT 1;",
            new { artnr });
    }

    public static Task<DB.Result<ProductModel>> GetAll()
    {
        return DB.QueryListAsync<ProductModel>(
            "SELECT * FROM sonex.products;");
    }
}
