using Prism.Mvvm;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.Models
{
    [SugarTable("dm_machine_record")]
    public class MachineRecord : BindableBase
    {
        /// 
        /// 主键 
        ///
        [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }
        /// 
        /// 设备id 
        ///
        [SugarColumn(ColumnName = "machine_id")]
        public string MachineId { get; set; }
        /// 
        /// 药品id 
        ///
        [SugarColumn(ColumnName = "drug_id")]
        public string DrugId { get; set; }
        [Navigate(NavigateType.ManyToOne, nameof(DrugId))]
        public DrugInfo DrugInfo { get; set; }
        /// 
        /// 数量 
        ///
        [SugarColumn(ColumnName = "quantity")]
        public int Quantity { get; set; }
        //[SugarColumn(ColumnName = "stock_quantity")]
        //public int? StockQuantity { get; set; }
        //[SugarColumn(ColumnName = "check_quantity")]
        //public int? CheckQuantity { get; set; }
        /// 
        /// 批号 
        ///
        [SugarColumn(ColumnName = "manu_no")]
        public string ManuNo { get; set; }
        /// 
        /// 操作人id 
        ///
        [SugarColumn(ColumnName = "operator")]
        public int? Operator { get; set; }
        [Navigate(NavigateType.ManyToOne, nameof(Operator))]
        public UserList User { get; set; }
        /// 
        /// 审核人id 
        ///
        [SugarColumn(ColumnName = "reviewer")]
        public int? Reviewer { get; set; }
        /// 
        /// 操作时间 
        /// 默认值: CURRENT_TIMESTAMP
        ///
        [SugarColumn(ColumnName = "operation_time")]
        public DateTime OperationTime { get; set; }
        /// 
        /// 效期 
        ///
        [SugarColumn(ColumnName = "eff_date")]
        public DateTime? EffDate { get; set; }
        /// 
        /// 出库入库类型(1入库2出库31还药32还空瓶,21药箱移出移入,69药箱替换,55绑定药品操作(绑定、解绑、修改基数)) 
        ///
        [SugarColumn(ColumnName = "type")]
        public int Type { get; set; }
        /// 
        ///操作类型(1放入药箱;0取走药箱) 
        ///
        [SugarColumn(ColumnName = "option_type")]
        public int OptionType { get; set; }
        /// 
        /// 出入库调拨单id 
        ///
        [SugarColumn(ColumnName = "invoice_id")]
        public string InvoiceId { get; set; }
        /// 
        /// 列号 
        ///
        [SugarColumn(ColumnName = "col_no")]
        public int ColNo { get; set; }
        /// 
        /// 抽屉号 
        ///
        [SugarColumn(ColumnName = "drawer_no")]
        public int DrawerNo { get; set; }
        /// 
        /// 取药科室 
        ///
        [SugarColumn(ColumnName = "department_id")]
        public string DepartmentId { get; set; }
        /// 
        /// 是否已经退药(0:没有1:还了部分2:完成) 
        /// 默认值: 0
        ///
        [SugarColumn(ColumnName = "status", IsOnlyIgnoreInsert = true)]
        public int Status { get; set; }
        /// 
        /// 退药量 
        /// 默认值: 0
        ///
        private int returnQuantity1;
        [SugarColumn(ColumnName = "return_quantity1", IsOnlyIgnoreInsert = true)]
        public int ReturnQuantity1 { get => returnQuantity1; set => SetProperty(ref returnQuantity1, value); }
        /// 
        /// 退空瓶量 
        /// 默认值: 0
        ///
        private int returnQuantity2;
        [SugarColumn(ColumnName = "return_quantity2", IsOnlyIgnoreInsert = true)]
        public int ReturnQuantity2 { get => returnQuantity2; set => SetProperty(ref returnQuantity2, value); }
        /// 
        /// 取药记录id 
        ///
        [SugarColumn(ColumnName = "get_id")]
        public int? GetId { get; set; }
        /// 
        /// 是否已经销毁 
        /// 默认值: 0
        ///
        [SugarColumn(ColumnName = "is_destroy", IsOnlyIgnoreInsert = true)]
        public int? IsDestroy { get; set; }
        /// 
        /// 销毁操作人 
        /// 默认值: 0
        ///
        [SugarColumn(ColumnName = "take_user", IsOnlyIgnoreInsert = true)]
        public string TakeUser { get; set; }
        /// 
        /// 销毁审核人 
        /// 默认值: 0
        ///
        [SugarColumn(ColumnName = "fuzeren", IsOnlyIgnoreInsert = true)]
        public string DestoryReviewerUser { get; set; }
        [SugarColumn(IsIgnore = true)]
        public int CanReturnQuantity
        {
            get => Quantity - ReturnQuantity1 - ReturnQuantity2;
        }
        [SugarColumn(IsIgnore = true)]
        public bool IsSelected { get; set; }
        /// 
        /// 已核销数量
        /// 
        private int hasCheckNum;
        [SugarColumn(IsIgnore = true)]
        public int HasCheckNum
        {
            get => hasCheckNum;
            set => SetProperty(ref hasCheckNum, value);
        }
        private int checkQuantity;
        /// 
        /// 核销数量
        /// 
        [SugarColumn(IsIgnore = true)]
        public int CheckQuantity
        {
            get => checkQuantity;
            set
            {
                if (value > Quantity - hasCheckNum)
                {
                    throw new ArgumentException("核销数量不能大于取药数量");
                }
                //退空瓶
                ReturnQuantity2 = value + hasCheckNum;
                //退药量
                ReturnQuantity1 = Quantity - value - hasCheckNum;
                SetProperty(ref checkQuantity, value);
            }
        }
        [Navigate(NavigateType.OneToMany, nameof(SurgicalScheduleDetail.GetRecordId))]
        public List _SurgicalScheduleDetailLst { get; set; }
    }
}