using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Reflection;

namespace Fab2ApprovalSystem.Models;

public class ECN : object {

    public string Title { get; set; }
    public int ECNNumber { get; set; }

    [DataType(DataType.Date)]
    public DateTime IssueDate { get; set; }

    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
    public DateTime? SubmitedDate { get; set; }

    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
    public DateTime? CloseDate { get; set; }
    public int OriginatorID { get; set; }
    public string OriginatorName { get; set; }
    // important!!make sure the id of the control matches the name of the field in the model  it is being binded to, 
    // in order to get the selected items from the control
    public List<int> DepartmentIDs { get; set; }
    public List<int> ModuleIDs { get; set; }
    public List<int> AreaIDs { get; set; }
    public List<int> TechnologyIDs { get; set; }
    public List<int> AcknowledgementByIDs { get; set; }
    public List<int> TrainingByIDs { get; set; }
    public bool IsECN { get; set; }
    public bool IsTECN { get; set; }
    public bool IsEmergencyTECN { get; set; }

    [DataType(DataType.Date)]
    public DateTime? ExpirationDate { get; set; }

    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
    public DateTime? ExtensionDate { get; set; }

    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
    public DateTime? CancellationDate { get; set; }
    public bool AcknowledgementRequired { get; set; }
    public bool TrainingRequired { get; set; }
    public int? AreaID { get; set; }
    public int? TechnologyID { get; set; }
    public bool PCRBRequired { get; set; }
    public string PCRBNumber { get; set; }
    public bool TestProgramChangeRequired { get; set; }
    public bool SPCChangeRequired { get; set; }
    public bool NewPartFlowRequired { get; set; }
    public bool SPNChangeRequired { get; set; }
    public string ImplementationDetails { get; set; }
    public int ImpactOnEnvironment { get; set; }
    public string ImpactOnEnvironmentDescription { get; set; }
    public int ImpactOnCapacity { get; set; }
    public string ImpactOnCapacityDescription { get; set; }
    public bool IsMA { get; set; }
    public bool IsRH { get; set; }
    public bool IsAU { get; set; }
    public bool IsIndustrial { get; set; }
    public int MaterialConsumptionChangeRequired { get; set; }
    public string MaterialConsumptionChangeDescription { get; set; }
    public string ReasonForChange { get; set; }
    public string DescriptionOfChange { get; set; }
    public bool NotAFlowChange { get; set; }
    public bool AttachECN_TECNToLots { get; set; }
    public bool SPNFlowChangeAtSingleStep { get; set; }
    public bool SPNFlowChangeAtMultipleSteps { get; set; }
    public byte CurrentStep { get; set; }
    public bool TECNExtensionState { get; set; }
    public bool Cancelled { get; set; }
    public bool CancellationApproved { get; set; }
    public bool CancellationInProgress { get; set; }
    public DateTime? CancellationApprovalDate { get; set; }
    public bool ExpirationProcessed { get; set; }
    public bool ExpirationInProgress { get; set; }
    public DateTime? ExpirationProcessedlDate { get; set; }
    public bool ReSubmitted { get; set; }
    public bool Converted { get; set; }
    public string ConvertedToType { get; set; }
    public int? ConvertedToNumber { get; set; }
    public int? ConvertedFromNumber { get; set; }
    public int WorkFlowNumber { get; set; }
    public bool LockedForConversion { get; set; }
    public bool ConversionRejected { get; set; }
    public bool ConversionApprovalInProgress { get; set; }
    public bool RecordLockIndicator { get; set; }
    public int RecordLockedBy { get; set; }
    public string RecordLockByName { get; set; }
    public DateTime? RecordLockedDate { get; set; }
    public int LastUpdatedBy { get; set; }
    public DateTime? LastUpdateDate { get; set; }
    public DateTime LastUpdateTimeStamp { get; set; }
    public int? CategoryID { get; set; }
    public bool FIChangeRequired { get; set; }
    public string NumberOfLotsAffected { get; set; }
    public bool? RecipeChange { get; set; }
    public List<int> ProductFamilyIDs { get; set; }
    public bool Deleted { get; set; }
    public bool IsDocEC { get; set; }
    public bool MetrologyChangeRequired { get; set; }
    public ECN() {
        DepartmentIDs = new List<int>();
        ModuleIDs = new List<int>();
        AreaIDs = new List<int>();
        TechnologyIDs = new List<int>();
        AcknowledgementByIDs = new List<int>();
        TrainingByIDs = new List<int>();
        ProductFamilyIDs = new List<int>();
    }

    public override bool Equals(object obj) {
        // If parameter is null return false.
        if (obj == null) {
            return false;
        }

        // If parameter cannot be cast to Point return false.
        ECN p = obj as ECN;
        if (p == null) {
            return false;
        }

        // Return true if the fields match:
        return (IsECN == p.IsECN) && (IsEmergencyTECN == p.IsEmergencyTECN);
    }

    public bool Equals(ECN p) {
        // If parameter is null return false:
        if (p == null) {
            return false;
        }

        foreach (PropertyInfo pi in p.GetType().GetProperties()) {
            foreach (PropertyInfo px in GetType().GetProperties()) {
                if (pi.Name.ToLower() == px.Name.ToLower()) {
                    if (pi.GetValue(p).Equals(px.GetValue(this)))
                        break;
                    else
                        return false;
                }
            }

        }

        return false;
        // Return true if the fields match:
    }

}

public class ECNAffectedDeparmtent {

    public int DepartmentID { get; set; }
    public string DepartmentName { get; set; }

}

public class ECNAffectedModule {

    public int ModuleID { get; set; }
    public string ModuleName { get; set; }

}

public class ECNCategory {

    public int CategoryID { get; set; }
    public string CategoryName { get; set; }

}

public class ECNAttachment {

    public int AttachmentID { set; get; }
    public int ECNNumber { get; set; }
    public string FileName { get; set; }
    public int UserID { get; set; }
    // extrafield
    public string FullName { get; set; }
    public string UploadDate { get; set; }
    public string Path { get; set; }

}

public class ECNArea {

    public int AreaID { set; get; }
    public string Area { get; set; }

}

public class ECNTechnology {

    public int TechnologyID { get; set; }
    public string Technology { get; set; }

}

public class ECNAcknowledgementTrainingBy {

    public int AcknowledgementTrainingByID { get; set; }
    public string AcknowledgementTrainingBy { get; set; }

}