using System;
using System.Collections.Generic;
using Sockeye.Biz;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;

namespace Sockeye.Models
{
    //NOTE: Any non required field (nullable in DB) sb nullable here, i.e. decimal? not decimal, 
    //otherwise the server will call it an invalid record if the field isn't sent from client

    public class License : ICoreBizObjectModel
    {
        public long Id { get; set; }
        public uint Concurrency { get; set; }

        public DateTime Created { get; set; }
        public bool Active { get; set; }//active licenses will be notified immediately on save and can be fetched by customer, inactive means still putting together or it's been kiboshed
        public bool NotificationSent { get; set; }
        public long? CustomerId { get; set; }
        [NotMapped]
        public string CustomerViz { get; set; }
        [Required]
        public ProductGroup PGroup { get; set; }
        public string RegTo { get; set; }
        public string Key { get; set; }
        public string FetchCode { get; set; }//v7 uses
        public string FetchEmail { get; set; }//v7 && v8 uses for notification, v7 uses for fetching manually in UI
        public DateTime? FetchedOn { get; set; }
        public string DbId { get; set; }//v8 uses

        public DateTime? LicenseExpire { get; set; }
        public DateTime MaintenanceExpire { get; set; }

        public bool Renewal { get; set; } = false;//v8/v7 modifies message and ops indicates it is a renewal of an existing license not a NEW license

        public bool TrialMode { get; set; } = false;//v8/v7 modifies message and ops indicates it was requested by user as trial request or manually created as a trial request in UI

        //v8 dto props
        [NotMapped]
        public int? CustomerUsers { get; set; }//v8 - subscription only
        [NotMapped]
        public int? MaxDataGB { get; set; }//v8 - subscription only
        
        
        //shared dto props
        [NotMapped]
        public int Users { get; set; }//v7 scheduled users, v8 internal users

        //V7 props for dto
        //not stored in db, hydrated if v7 license and
        //used to do the generation from selections at client
        [NotMapped]
        public bool WBI { get; set; }
        [NotMapped]
        public DateTime? WBIExpires { get; set; }
        [NotMapped]
        public bool MBI { get; set; }
        [NotMapped]
        public DateTime? MBIExpires { get; set; }
        [NotMapped]
        public bool RI { get; set; }
        [NotMapped]
        public DateTime? RIExpires { get; set; }
        [NotMapped]
        public bool QBI { get; set; }
        [NotMapped]
        public DateTime? QBIExpires { get; set; }
        [NotMapped]
        public bool QBOI { get; set; }
        [NotMapped]
        public DateTime? QBOIExpires { get; set; }
        [NotMapped]
        public bool PTI { get; set; }
        [NotMapped]
        public DateTime? PTIExpires { get; set; }
        [NotMapped]
        public bool QuickNotification { get; set; }
        [NotMapped]
        public DateTime? QuickNotificationExpires { get; set; }
        [NotMapped]
        public bool ExportToXLS { get; set; }
        [NotMapped]
        public DateTime? ExportToXLSExpires { get; set; }
        [NotMapped]
        public bool OutlookSchedule { get; set; }
        [NotMapped]
        public DateTime? OutlookScheduleExpires { get; set; }
        [NotMapped]
        public bool OLI { get; set; }
        [NotMapped]
        public DateTime? OLIExpires { get; set; }
        [NotMapped]
        public bool ImportExportCSVDuplicate { get; set; }
        [NotMapped]
        public DateTime? ImportExportCSVDuplicateExpires { get; set; }


        public string Wiki { get; set; }
        public List<string> Tags { get; set; }

        //workaround for notification    
        [NotMapped, JsonIgnore]
        public string Name { get; set; }

        public License()
        {
            Tags = new List<string>();
        }

        [NotMapped, JsonIgnore]
        public SockType SType { get => SockType.License; }

    }//eoc

}//eons
/*
   await ExecQueryAsync("CREATE TABLE alicense (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created TIMESTAMPTZ NOT NULL, "
                        + "customerid BIGINT NOT NULL REFERENCES acustomer(id), regto TEXT NOT NULL,  key TEXT NOT NULL, fetchcode TEXT, fetchemail TEXT, "
                        + "fetchedon TIMESTAMPTZ,  dbid TEXT, licenseexpire TIMESTAMPTZ, maintenanceexpire TIMESTAMPTZ NOT NULL, "
                        + "wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
*/