using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace LHDN.CRM.Models.ViewModels
{
    public class AttachmentViewModel
    {
        public long AttachmentID { get; set; }
        public long? TempAttachmentID { get; set; }
        public long ID { get; set; } //ActivityID

        private string _FileName { get; set; }
        public string FileName
        {
            get
            {
                return _FileName;
            }
            set {
                _FileName = value;

                FileType = getFiletype();
            }
        }

        private string _FileContentType { get; set; }
        public string FileContentType
        {
            get
            {
                return _FileContentType;
            }

            set
            {
                _FileContentType = value;

                FileType = getFiletype();

            }
        }
        public byte[] FileContent { get; set; }
        public string CatatanType { get; set; }

        public string FileType { get; set; }

        //public AttachmentViewModel()
        //{
        //    FileType = getFiletype();
        //}

        private string getFiletype()
        {
            if (FileContentType == null || FileName == null) { return ""; }
            Regex regex = new Regex(@"^image\/.+");
            if (regex.IsMatch(FileContentType) == true)
            {
                return "image";
            }
            else
            {
                return Path.GetExtension(FileName).ToLower();
            }

        }
    }
}
