using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using Fab2ApprovalSystem.ViewModels;
using System.Web.Mvc;
using System.Text.RegularExpressions;

namespace Fab2ApprovalSystem.Models
{
    public class CredentialsStorage
    {
        public string UserName { get; set; }
        public string Password { get; set; }
    }

    public class Lot
    {
        public int LotID { get; set; }
        [Display(Name = "Wafer Lot#")]
        public string LotNumber { get; set; }
        // public string ParentLotNumber { set; get { return LotNumber.Length >= 7 ? LotNumber.Substring(0, 7) : LotNumber; } }
        public string ParentLotNumber { set; get; }

        public int MRBNumber { get; set; }
        public string MRBDispoType { get; set; }
        public bool GoodToSubmit { get; set; }
        public string SubmitErrorMessage { get; set; }
        // Lot Disposition Issue Number
        public int IssueID { get; set; }
        public string IssueIDWithoutMRB { get; set; }
        public string DieLotNumber { get; set; }
        public string Description { get; set; }
        [Display(Name = "New PN#")]
        public string NewPartNo { get; set; }
        [Display(Name = "WIP PN#")]
        public string WipPartNo { get; set; }
        [Display(Name = "Die PN#")]
        public string DiePartNo { get; set; }
        [Display(Name = "Device Type")]
        public string ProductFamily { get; set; }
        public string Gen { get; set; }
        public string Channel { get; set; }
        public string Hexsize { get; set; }
        public double Voltage { get; set; }
        public int WaferCount { get; set; }
        public int ReleaseCount { get; set; }
        public int ScrapCount { get; set; }
        public int DieCount { get; set; }
        public string Location { get; set; }
        public double TotalCost { get; set; }
        public int LotStatusOptionID { get; set; }
        public string LotStatusOptionName { get; set; }
        public double WaferCost { get; set; }
        public double DieCost { get; set; }

        [UIHint("LotStatusOptionTemplate")]
        [Display(Name = "Lot Status")]
        public LotStatusOptionViewModel LotStatusOption { get; set; }

        public ScrapLot ScrapLotWafer { get; set; }

        [Display(Name = "Lot Dispos")]
        public string OtherLotDispos { get; set; }

        //MRB Lot
        //[CustomDispoTypeValidationAttribute(ErrorMessage = "The values can only either A or B or C or D")]
        public char? DispoType { get; set; }
        [Display(Name = "Lot Dispos")]
        public string LotDispositionsLinkedToLot { get; set; }

        [Display(Name = "MRBs")]
        public string MRBsLinkedToLot { get; set; }

        public string Status { get; set; }

        public int OpenIssueWithExistingLots { get; set; }
        public string QualityCode { get; set; }

        [Display(Name = "Source Lot#")]
        public string SourceLot { get; set; }
        public string SourceAction { get; set; }
        public DateTime? SourceActionTime { get; set; }
        public DateTime? SPNTransmitTime { get; set; }
        public string SPNTransmitMsg { get; set; }
        [Display(Name = "MRBs")]
        public string OtherMRBs { get; set; }

        public Lot()
        {
            LotStatusOption = new LotStatusOptionViewModel();
            ScrapLotWafer = new ScrapLot();
            
        }

        public bool IsDirty { get; set; }

    }

    public class MRBHoldFlagReport
    {
        public string LotNo { get; set; }
        public string TransactionType { get; set; }

        public string PartNo { get; set; }
        public string CurrentLocation { get; set; }
        public string CurrentOperation { get; set; }
        public int StartQty { get; set; }
        public int CurrentQty { get; set; }
        public string LotStatus { get; set; }
        public string OperStatus { get; set; }
        public string Successful { get; set; }
        public string Comment { get; set; }

        public string PriorMRBHoldLocation { get; set; }
        public string PriorMRBHoldOperation { get; set; }
        public string PriorMRB_DispoType { get; set; }

        public string CurrentMRBHoldLocation { get; set; }
        public string CurrentMRBHoldOperation { get; set; }
        public string CurrentMRB_DispoType { get; set; }


        public string MRB_DispoType { get; set; }
        public DateTime TransactionDateTime { get; set; }
        public string MRBLocation { get; set; }
        public string MRBOperation { get; set; }

        public bool Reprocess { get; set; }

        public bool HasErrors { get; set; }


    }

    public class MRBLotsTobeSentToSPN
    {
        public string LotNumber { get; set; }
        public int MRBNumber { get; set; }
        public char? DispoType { get; set; }
        public char AddRemoveChangeMRBFlag { get; set; }
        public bool IsDirty { get; set; }
        public bool SentToSPN { get; set; }
       public DateTime MRBLotLastSentToSPNDatetime { get; set; }
      
    }

    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
        public class CustomDispoTypeValidationAttribute : ValidationAttribute, IClientValidatable
        {
            public override bool IsValid(object value)
            {
                char tem = (char)value;
                var productName = tem.ToString();
                if (!string.IsNullOrEmpty(productName))
                {
                    return Regex.IsMatch(productName, "^[A,B,C,D]");
                }
                return true;
            }

            public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
            {
                yield return new ModelClientValidationRule
                {
                    ErrorMessage = ErrorMessage,
                    ValidationType = "dispotypevalidation"
                };
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public class Department
        {
            //public int LotDispoDepartmentID { get; set; }
            //public int IssueID { get; set; }
            public int DepartmentID { get; set; }
            public string DepartmentName { get; set; }
        }

    /// <summary>
    /// 
    /// </summary>
        public class AffectedModule
        {
            public int ModuleID { get; set; }
            public string ModuleName { get; set; }

        }

        public class WIPPart
        {
            public string WIPPartData { get; set; }
            public string PartNumber { get; set; }
            public string SiliconPartNumber { get; set; }
            public string ProcessFlow { get; set; }
        }

        public class ProductFamilies
        {
            public int ProductFamilyID { get; set; }
            public string ProductFamily { get; set; }
        }

    public class LotSplitAnalysisResult
    {
        public int ID { get; set; }
        public string ParentLotNo { get; set; }
        public string LotNo { get; set; }
        public DateTime ActionTime { get; set; }
        public string ActionType { get; set; }
        public bool? IsAffected { get; set; }
    }

}