using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unibase.Data.Expressions;
using Unibase.Data.Sorting;
using Unibase.Data.Sql;
using Unibase.Platform.Data;

namespace Bizgaze.CRM.Visitors.Infos
{
    public class Visitor : BaseInfo, IInfo
    {
        public enum Property
        {
            VisitorId, StageId, TenantId, StatusId, PurposeOfVisit, Title, SeriesId, Code, Reason, EmailId, ComingFrom, VersionguId, MobileNumber, FullName, NewCheckIn, PreInvite, AccessCode, FutureInvitation, TimeOfVisit, DateOfVisit, HostName, OrganizationName, TitleName, VisitorType, TemplateId, Installedappid,PhotoUrl, CreatedDate, StageStatusName, RefStatusId

        }
        #region Public Properties
        public Int64 VisitorId { get; set; }       
        public Int32 PurposeOfVisit { get; set; }
        public int Title { get; set; }
        public int VisitorType { get; set; }
        public Int64 SeriesId { get; set; }
        public Int64 EmployeeId { get; set; }
        public Int64 TemplateId { get; set; }
        public int RefStatusId { get; set; }
        public long Installedappid { get; set; }
        public string Code { get; set; }
        public string Reason { get; set; }
        public string EmailId { get; set; }
        public string ComingFrom { get; set; }
        //public string VersionguId { get; set; }
        public string MobileNumber { get; set; }
        public string PurposeOfVisitType { get; set; }
        public string HostName { get; set; }
        public string FullName { get; set; }
        public string OrganizationName { get; set; }
        public string NewCheckIn { get; set; }
        public string PreInvite { get; set; }
        public string TitleName { get; set; }
        public string StageStatusName { get; set; }
        public string AccessCode { get; set; }
        public Boolean FutureInvitation { get; set; }

        public DateTime TimeOfVisit { get; set; }
        public DateTime DateOfVisit { get; set; }
        public Boolean Agreement { get; set; }
        public string PhotoUrl { get; set; }
        #endregion

        public string __TableName
        {
            get
            {
                return "bizgazecrm_visitors";
            }
        }
        public SortList GetDefaultSort()
        {
            return new SortList()
            {
                new Sort("VisitorId", Unibase.Data.Enums.SortOrder.Desc)
            };
        }
        public override Select GetQuery()
        {
            string[] columns = {
                "v.mobilenumber",
                "v.employeeid",
                "v.photourl",
                "v.installedappid",
                "v.organizationname",
                "v.comingfrom",
                "v.accesscode",
                "v.visitorid",
                "v.code",
                "v.emailid",
                "v.FullName",
                "v.title",
                "v.FutureInvitation",
                "v.TimeOfVisit",
                "v.DateOfVisit",
                "v.CreatedDate",
                 "v.purposeofvisit",
                 "ss.stagestatusname",
                 "ss.refstatusid",
                "Case when purposeofvisit=1 then 'Interview'  when purposeofvisit=2 then 'Official Meeting'  when purposeofvisit=3 then 'Meeting an Employee'  when purposeofvisit=4 then 'Package Delivery' when purposeofvisit=5 then 'Others' end as purposeofvisittype",
                "concat(e.firstname, e.lastname) AS HostName",
                "Case when title=1 then 'Mr'  when title=2  then 'Miss' end as TitleName",
                };
            var a = new Select("bizgazecrm_visitors v").Columns(columns).
               InnerJoin("bizgazecrm_employees e", Exp.EqColumns("e.employeeid", "v.employeeid")).InnerJoin("unibase_stages s",Exp.EqColumns("v.stageid","s.stageid")).InnerJoin("unibase_stagestatus ss", Exp.EqColumns("ss.stagestatusid", "s.stagestatusid"));
            return a;
        }
    }
}
