using LinqToDB.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace MasaBlazorApp3.Pojo
{
    [Table("drug_info")]
    public class DrugInfo
    {
        [PrimaryKey]
        [Column("drug_id")]
        public string DrugId {  get; set; }

        [Column("drug_name")]
        public string DrugName { get; set;}

        [Column("drug_type")]
        public string DrugType { get; set;}

        [Column("drug_spec")]
        public string DrugSpec { get; set;}


        [Column("manufactory")]
        public string Manufactory { get; set; }

        [Column("pack_unit")]
        public string PackUnit { get; set; }
        [Column("py_code")]
        public string PyCode { get; set; }
        [Column("pack_h")]
        public string PackH { get; set; }
        //用于标识“手术室患者麻醉药品使用登记本”报表中是否导出该药品 1导出0不导
        //[Column("pack_h")]
        //public int ReportType { get; set; }
        [Column(IsColumn =false)]
        public string DrugNameSpecManufactory 
        {
            get => DrugName + " / " + DrugSpec+ " / " + Manufactory+" / " + PyCode+" / " + DrugId;
        }


        [Association(ThisKey = nameof(DrugId), OtherKey = nameof(ChannelStock.DrugId))]
        public List<ChannelStock> Stocks { get; set;} = new List<ChannelStock>();


        [Association(ThisKey = nameof(DrugId), OtherKey = nameof(DrugManuNo.DrugId))]
        public List<DrugManuNo> Manus { get; set; } = new List<DrugManuNo>();

        [Column(IsColumn = false)]
        public int StockQuantity
        {
            get { return Stocks.Aggregate(0, (current, next) => current + next.Quantity); }
        }
        //药盒基数
        [Column(IsColumn = false)]
        public int BoxBaseQuantity
        {
            get { return Stocks.Aggregate(0, (current, next) => current+next.BaseQuantity);}
        }

        public override bool Equals(object o)
        {
            var other = o as DrugInfo;

            return other?.DrugId == DrugId;
        }

        public override string ToString()
        {
            return $"名称: {DrugName},规格：{DrugSpec}";
        }

        [Column(IsColumn = false)]
        public string DrugNameSpec
        {
            get => DrugName + " ; " + DrugSpec + ";"+ Manufactory;
        }

        [Column(IsColumn =false)]
        public string set_manu_no { get; set; }
        [Column(IsColumn =false)]
        public string set_eff_Date { get; set; }
    }
}
