using BS.Shared;
using BS.Shared.DataContracts;
using System;

namespace BeWo.ViewModel
{
    public class FileAttachmentVM : AbstractDCMapperVM<FileAttachmentDC>
    {

        public static string PropertyName_Description = "Description";

        public static string PropertyName_Folder = "Folder";

        public static string PropertyName_FileName = "FileName";

        public static string PropertyName_FileAttachmentType = "FileAttachmentType";

        public static string PropertyName_InsertedBy = "InsertedBy";

        public static string PropertyName_InsertedOn = "InsertedOn";

        public static string PropertyName_IsLocked = "IsLocked";

        public static string PropertyName_LockedBy = "LockedBy";

        public static string PropertyName_URL = "URL";

        //private byte[] _Data;

        private BeWoFolderVM _Folder;

        private string _Description;

        private string _FileName;

        private string _InsertedBy;

        private DateTime _InsertedOn;

        private bool _IsLocked;

        private string _URL;

        private FileAttachmentType _FileAttachmentType;

        public FileAttachmentVM(FileAttachmentDC pDC)
            : base(pDC, true)
        {
        }


        public virtual BeWoFolderVM Folder
        {
            get { return this._Folder; }

            set
            {
                if (this.AreDifferent(this._Folder, value))
                {
                    this._Folder = value;
                }
            }
        }

        public FileAttachmentType FileAttachmentType
        {
            get { return this._FileAttachmentType; }

            set
            {
                if (this.AreDifferent(this._FileAttachmentType, value))
                {
                    this._FileAttachmentType = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.FileAttachmentType, value), PropertyName_FileAttachmentType);
                    this.FirePropertyChanged(PropertyName_FileAttachmentType);
                }
            }
        }

        public string Description
        {
            get
            {
                return _Description;
            }
            set
            {
                if (this.AreDifferent(this._Description, value))
                {
                    this._Description = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Description, value), PropertyName_Description);
                    this.FirePropertyChanged(PropertyName_Description);
                }
            }
        }

        public string FileName
        {
            get
            {
                return _FileName;
            }
            set
            {
                if (this.AreDifferent(this._FileName, value))
                {
                    this._FileName = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.FileName, value), PropertyName_FileName);
                    this.FirePropertyChanged(PropertyName_FileName);
                }
            }
        }

        public string InsertedBy
        {
            get
            {
                return _InsertedBy;
            }
            set
            {
                if (this.AreDifferent(this._InsertedBy, value))
                {
                    this._InsertedBy = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.InsertedBy, value), PropertyName_InsertedBy);
                    this.FirePropertyChanged(PropertyName_InsertedBy);
                }
            }
        }

        public DateTime InsertedOn
        {
            get
            {
                return _InsertedOn;
            }
            set
            {
                if (this.AreDifferent(this._InsertedOn, value))
                {
                    this._InsertedOn = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.InsertedOn, value), PropertyName_InsertedOn);
                    this.FirePropertyChanged(PropertyName_InsertedOn);
                }
            }
        }

        public bool IsLocked
        {
            get
            {
                return _IsLocked;
            }
            set
            {
                if (this.AreDifferent(this._IsLocked, value))
                {
                    this._IsLocked = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.IsLocked, value), PropertyName_IsLocked);
                    this.FirePropertyChanged(PropertyName_IsLocked);
                }
            }
        }

        public string URL
        {
            get
            {
                return _URL;
            }
            set
            {
                if (this.AreDifferent(this._URL, value))
                {
                    this._URL = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.URL, value), PropertyName_URL);
                    this.FirePropertyChanged(PropertyName_URL);
                }
            }
        }

        protected override void InitByDataContract(FileAttachmentDC pDataContract)
        {
            this._Description = pDataContract.Description;
            this._FileAttachmentType = pDataContract.FileAttachmentType;
            this._FileName = pDataContract.FileName;
            //this._Folder = pDataContract.fo;
            this._InsertedBy = pDataContract.InsertedBy;
            this._InsertedOn = pDataContract.InsertedOn;
            this._IsLocked = pDataContract.IsLocked;
            this._URL = pDataContract.URL;

        }

        protected override FileAttachmentDC MapToDataContract(FileAttachmentDC pDataContract, bool doCommit)
        {
            pDataContract.Description = _Description;
            pDataContract.FileAttachmentType = _FileAttachmentType;
            pDataContract.FileName = _FileName;

            if (_Folder != null)
            {
                pDataContract.BeWoFolderOid = _Folder.DataContract.BeWoFolderOid;
                pDataContract.ObjectOid = Folder.DataContract.ObjectOid;
                pDataContract.ObjectTid = Folder.DataContract.ObjectTid;
            }
            
            pDataContract.InsertedBy = _InsertedBy;
            pDataContract.InsertedOn = _InsertedOn;
            pDataContract.IsLocked = _IsLocked;
            pDataContract.URL = _URL;

            return pDataContract;
        }
    }
}