using System.Collections.Generic;
using Microsoft.Extensions.Logging;

namespace Sockeye.Biz
{

    /// <summary>
    /// roles of all business objects
    /// </summary>
    internal static class BizRoles
    {

        //NOTE: this *is* efficient, it's static and initialized once only on startup the first time it's required and re-used forever afterwards until next reboot

        internal static Dictionary<SockType, BizRoleSet> roles = new Dictionary<SockType, BizRoleSet>();

        static BizRoles()
        {

            //Add all object roles here
            //NOTE: do not need to add change roles to read roles, Authorized.cs takes care of that automatically 
            //by assuming if you can change you can read

            //HOW THIS WORKS / WHATS EXPECTED
            //Change = CREATE, RETRIEVE, UPDATE, DELETE - Full rights            
            //ReadFullRecord = You can read *all* the fields of the record, but can't modify it. Change is automatically checked for so only add different roles from change 
            //SELECT - this role allows user to select (fetch picklist) this type of object on other forms, we have this security level because otherwise a Customer role user for example, could see other customers via api if not prohibited
            //  Setting SELECT - Select only needs to be set on objects for which there is a defined PickList object because that's where it's used solely (as of now anyway)
            //DELETE = There is no specific delete right for now though it's checked for by routes in Authorized.cs in case we want to add it in future as a separate right from create.

            #region All roles initialization
            //CoreBizObject add here


            //BizRules will handle finer grained rights, this is just the big picture rights or default if no finer required

            ////////////////////////////////////////////////////////////
            //CUSTOMER
            //  (any change copy to customer notes, head office)          
            roles.Add(SockType.Customer, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.Tech
                                 | AuthorizationRoles.SalesRestricted
                                 ,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //CUSTOMERNOTES
            // (duplicate of customer above but required to be here to allow various code to not bomb)
            roles.Add(SockType.CustomerNote, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.SalesRestricted
                                 | AuthorizationRoles.Tech
                                 ,
                Select = AuthorizationRoles.All
            });


            ////////////////////////////////////////////////////////////
            //CUSTOMER PROXY NOTIFICATION SUBSCRIPTIONS
            //   
            roles.Add(SockType.CustomerNotifySubscription, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.Tech
                                 | AuthorizationRoles.SalesRestricted
                                 ,
                Select = AuthorizationRoles.All
            });



            ////////////////////////////////////////////////////////////
            //HeadOffice (duplicate of customer)
            //            
            roles.Add(SockType.HeadOffice, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.SalesRestricted
                                 | AuthorizationRoles.Tech
                                 ,
                Select = AuthorizationRoles.All
            });


            ////////////////////////////////////////////////////////////
            //GLOBAL BIZ SETTINGS
            //
            roles.Add(SockType.Global, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
            });


            ////////////////////////////////////////////////////////////
            //GLOBAL OPS SETTINGS
            // 
            roles.Add(SockType.GlobalOps, new BizRoleSet()
            {
                Change = AuthorizationRoles.OpsAdmin,
                ReadFullRecord = AuthorizationRoles.OpsAdminRestricted
            });


            ////////////////////////////////////////////////////////////
            //USER
            //            
            roles.Add(SockType.User, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //USEROPTIONS
            //(Identical to User, though route also allows own record access full changes)
            //            
            roles.Add(SockType.UserOptions, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
            });

            ////////////////////////////////////////////////////////////
            //SERVERSTATE
            //
            roles.Add(SockType.ServerState, new BizRoleSet()
            {
                Change = AuthorizationRoles.OpsAdmin,
                ReadFullRecord = AuthorizationRoles.All
            });


            ////////////////////////////////////////////////////////////
            //LOGFILE - server log, not event log
            //
            roles.Add(SockType.LogFile, new BizRoleSet()
            {
                Change = AuthorizationRoles.NoRole,
                ReadFullRecord = AuthorizationRoles.OpsAdmin | AuthorizationRoles.OpsAdminRestricted
            });


            ////////////////////////////////////////////////////////////
            //BACKUP
            //Only opsfull can change Backup
            //ops and biz admin can view Backup        
            roles.Add(SockType.Backup, new BizRoleSet()
            {
                Change = AuthorizationRoles.OpsAdmin,
                ReadFullRecord = AuthorizationRoles.OpsAdminRestricted | AuthorizationRoles.BizAdmin | AuthorizationRoles.BizAdminRestricted
            });


            ////////////////////////////////////////////////////////////
            //FILEATTACHMENT ADMINISTRATION
            //This is not for attachments themselves which are tied to the object they are attached to
            //this is for things like maintenance jobs or viewing lists of all attachments in general for batch ops etc
            //  NOTE: Attachments are considered business data and as such are not available to OPS roles
            // who are not allowed to see biz data    
            roles.Add(SockType.FileAttachment, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin,//Need full rights only here because this is the rights checked for batch delete etc so it's simpler than checking all the parent object rights if you know they already have all rights
                ReadFullRecord = AuthorizationRoles.BizAdmin | AuthorizationRoles.BizAdminRestricted
            });


            ////////////////////////////////////////////////////////////
            //OPERATIONS / JOBS
            //Only opsfull can change operations
            //ops and biz admin can view operations        
            roles.Add(SockType.ServerJob, new BizRoleSet()
            {
                Change = AuthorizationRoles.OpsAdmin,
                ReadFullRecord = AuthorizationRoles.OpsAdminRestricted | AuthorizationRoles.BizAdmin | AuthorizationRoles.BizAdminRestricted
            });

            ////////////////////////////////////////////////////////////
            //OPERATIONS / Notification settings
            //Only opsfull can change operations
            //ops and biz admin can view operations        
            roles.Add(SockType.OpsNotificationSettings, new BizRoleSet()
            {
                Change = AuthorizationRoles.OpsAdmin,
                ReadFullRecord = AuthorizationRoles.OpsAdminRestricted | AuthorizationRoles.BizAdmin | AuthorizationRoles.BizAdminRestricted
            });


            ////////////////////////////////////////////////////////////
            //SERVERMETRICS
            //
            roles.Add(SockType.ServerMetrics, new BizRoleSet()
            {
                Change = AuthorizationRoles.OpsAdmin,//this is to turn on extra metrics (profiler)
                ReadFullRecord = AuthorizationRoles.OpsAdmin | AuthorizationRoles.OpsAdminRestricted
            });


            ////////////////////////////////////////////////////////////
            //TRANSLATION
            //
            roles.Add(SockType.Translation, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin,
                //Anyone can read it because they need to to open a form, but also in UI
                //only the BizAdminRestricted actually gets a link to see the customization page
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted,
                Select = AuthorizationRoles.All
            });


            ////////////////////////////////////////////////////////////
            //DATALISTFILTER
            //
            roles.Add(SockType.DataListSavedFilter, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin,
                ReadFullRecord = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //FORMUSEROPTIONS
            // Note: this is only ever modified by user personally
            // so it is accessible by all and biz rules
            //restrict to own userid
            roles.Add(SockType.FormUserOptions, new BizRoleSet()
            {
                Change = AuthorizationRoles.All,
                ReadFullRecord = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //FORMCUSTOM
            //
            roles.Add(SockType.FormCustom, new BizRoleSet()
            {
                //Only BizAdmin can modify forms
                Change = AuthorizationRoles.BizAdmin,
                //Anyone can read it because they need to to open a form, but also in UI
                //only the BizAdminRestricted actually gets a link to see the customization page
                ReadFullRecord = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //PICKLISTTEMPLATE
            //
            roles.Add(SockType.PickListTemplate, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin,
                ReadFullRecord = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //BIZMETRICS
            //  todo: deprecate?  Not used for anything as of nov 2020  
            roles.Add(SockType.BizMetrics, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted |
                AuthorizationRoles.Sales |
                AuthorizationRoles.SalesRestricted |
                AuthorizationRoles.Accounting
            });

            ////////////////////////////////////////////////////////////
            //NOTIFICATION
            //
            roles.Add(SockType.Notification, new BizRoleSet()
            {
                Change = AuthorizationRoles.All,
                ReadFullRecord = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //NOTIFICATION_SUBSCRIPTION
            //
            roles.Add(SockType.NotifySubscription, new BizRoleSet()
            {
                Change = AuthorizationRoles.All,
                ReadFullRecord = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //REPORT
            //            
            roles.Add(SockType.Report, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin | AuthorizationRoles.BizAdminRestricted,
                ReadFullRecord = AuthorizationRoles.All,
                Select = AuthorizationRoles.All
            });





            ////////////////////////////////////////////////////////////
            //MEMO
            // (everyone but outside users Customer and HO can send and receive memos)
            roles.Add(SockType.Memo, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminRestricted
                | AuthorizationRoles.BizAdmin
                | AuthorizationRoles.ServiceRestricted
                | AuthorizationRoles.Service
                | AuthorizationRoles.InventoryRestricted
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.TechRestricted
                | AuthorizationRoles.Tech
                | AuthorizationRoles.SubContractorRestricted
                | AuthorizationRoles.SubContractor
                | AuthorizationRoles.Sales
                | AuthorizationRoles.SalesRestricted
                | AuthorizationRoles.OpsAdminRestricted
                | AuthorizationRoles.OpsAdmin,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                | AuthorizationRoles.BizAdmin
                | AuthorizationRoles.ServiceRestricted
                | AuthorizationRoles.Service
                | AuthorizationRoles.InventoryRestricted
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.TechRestricted
                | AuthorizationRoles.Tech
                | AuthorizationRoles.SubContractorRestricted
                | AuthorizationRoles.SubContractor
                | AuthorizationRoles.Sales
                | AuthorizationRoles.SalesRestricted
                | AuthorizationRoles.OpsAdminRestricted
                | AuthorizationRoles.OpsAdmin,
                Select = AuthorizationRoles.BizAdminRestricted
                | AuthorizationRoles.BizAdmin
                | AuthorizationRoles.ServiceRestricted
                | AuthorizationRoles.Service
                | AuthorizationRoles.InventoryRestricted
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.TechRestricted
                | AuthorizationRoles.Tech
                | AuthorizationRoles.SubContractorRestricted
                | AuthorizationRoles.SubContractor
                | AuthorizationRoles.Sales
                | AuthorizationRoles.SalesRestricted
                | AuthorizationRoles.OpsAdminRestricted
                | AuthorizationRoles.OpsAdmin,
            });

            ////////////////////////////////////////////////////////////
            //REMINDER
            // (everyone but outside users Customer and HO)
            roles.Add(SockType.Reminder, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminRestricted
                | AuthorizationRoles.BizAdmin
                | AuthorizationRoles.ServiceRestricted
                | AuthorizationRoles.Service
                | AuthorizationRoles.InventoryRestricted
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.TechRestricted
                | AuthorizationRoles.Tech
                | AuthorizationRoles.SubContractorRestricted
                | AuthorizationRoles.SubContractor
                | AuthorizationRoles.Sales
                | AuthorizationRoles.SalesRestricted
                | AuthorizationRoles.OpsAdminRestricted
                | AuthorizationRoles.OpsAdmin,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                | AuthorizationRoles.BizAdmin
                | AuthorizationRoles.ServiceRestricted
                | AuthorizationRoles.Service
                | AuthorizationRoles.InventoryRestricted
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.TechRestricted
                | AuthorizationRoles.Tech
                | AuthorizationRoles.SubContractorRestricted
                | AuthorizationRoles.SubContractor
                | AuthorizationRoles.Sales
                | AuthorizationRoles.SalesRestricted
                | AuthorizationRoles.OpsAdminRestricted
                | AuthorizationRoles.OpsAdmin,
                Select = AuthorizationRoles.BizAdminRestricted
                | AuthorizationRoles.BizAdmin
                | AuthorizationRoles.ServiceRestricted
                | AuthorizationRoles.Service
                | AuthorizationRoles.InventoryRestricted
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.TechRestricted
                | AuthorizationRoles.Tech
                | AuthorizationRoles.SubContractorRestricted
                | AuthorizationRoles.SubContractor
                | AuthorizationRoles.Sales
                | AuthorizationRoles.SalesRestricted
                | AuthorizationRoles.OpsAdminRestricted
                | AuthorizationRoles.OpsAdmin,
            });

            ////////////////////////////////////////////////////////////
            //REVIEW
            // (everyone but outside users  and follows object rights)
            roles.Add(SockType.Review, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminRestricted
                | AuthorizationRoles.BizAdmin
                | AuthorizationRoles.ServiceRestricted
                | AuthorizationRoles.Service
                | AuthorizationRoles.InventoryRestricted
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.TechRestricted
                | AuthorizationRoles.Tech
                | AuthorizationRoles.SubContractorRestricted
                | AuthorizationRoles.SubContractor
                | AuthorizationRoles.Sales
                | AuthorizationRoles.SalesRestricted
                | AuthorizationRoles.OpsAdminRestricted
                | AuthorizationRoles.OpsAdmin,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                | AuthorizationRoles.BizAdmin
                | AuthorizationRoles.ServiceRestricted
                | AuthorizationRoles.Service
                | AuthorizationRoles.InventoryRestricted
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.TechRestricted
                | AuthorizationRoles.Tech
                | AuthorizationRoles.SubContractorRestricted
                | AuthorizationRoles.SubContractor
                | AuthorizationRoles.Sales
                | AuthorizationRoles.SalesRestricted
                | AuthorizationRoles.OpsAdminRestricted
                | AuthorizationRoles.OpsAdmin,
                Select = AuthorizationRoles.BizAdminRestricted
                | AuthorizationRoles.BizAdmin
                | AuthorizationRoles.ServiceRestricted
                | AuthorizationRoles.Service
                | AuthorizationRoles.InventoryRestricted
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.TechRestricted
                | AuthorizationRoles.Tech
                | AuthorizationRoles.SubContractorRestricted
                | AuthorizationRoles.SubContractor
                | AuthorizationRoles.Sales
                | AuthorizationRoles.SalesRestricted
                | AuthorizationRoles.OpsAdminRestricted
                | AuthorizationRoles.OpsAdmin,
            });

            ////////////////////////////////////////////////////////////
            //INTEGRATION 
            //  (every unrestricted inside user and not subcontractor)
            //this right is for the integration data itself, NOT any other Sockeye data
            //so if someone is malicious the worst case scenario is they can mess up the integration data
            // but they would still need rights to access any Sockeye data under their account so there is no loophole here
            // technically an integration may be used by any role user
            // however not likely to be read only or limited rights roles
            // so will allow full access for any non restricted user and leave
            // finer tuning of authorization to integrating app itself
            // Also, integration is only used to store app data conveniently it in no way is required to 
            // write api accessing apps so any limitations are not preventing 3rd parties from writing Sockeye api consuming apps of any kind
            //
            roles.Add(SockType.Integration, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                | AuthorizationRoles.Service
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.Tech
                | AuthorizationRoles.Sales
                | AuthorizationRoles.OpsAdmin,
                ReadFullRecord = AuthorizationRoles.BizAdmin
                | AuthorizationRoles.Service
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.Tech
                | AuthorizationRoles.Sales
                | AuthorizationRoles.OpsAdmin,
                Select = AuthorizationRoles.BizAdmin
                | AuthorizationRoles.Service
                | AuthorizationRoles.Inventory
                | AuthorizationRoles.Accounting
                | AuthorizationRoles.Tech
                | AuthorizationRoles.Sales
                | AuthorizationRoles.OpsAdmin,
            });


            ////////////////////////////////////////////////////////////
            //LICENSE
            //          
            roles.Add(SockType.Vendor, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.Tech
                                 | AuthorizationRoles.SalesRestricted
                                 ,
                Select = AuthorizationRoles.All
            });


            ////////////////////////////////////////////////////////////
            //LICENSE
            //          
            roles.Add(SockType.License, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.Tech
                                 | AuthorizationRoles.SalesRestricted
                                 ,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //TRIALLICENSEREQUEST
            //        
            roles.Add(SockType.TrialLicenseRequest, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.Tech
                                 | AuthorizationRoles.SalesRestricted
                                 ,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //SUBSCRIPTIONSERVER
            //           
            roles.Add(SockType.SubscriptionServer, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.Tech
                                 | AuthorizationRoles.SalesRestricted
                                 ,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //PURCHASE
            //         
            roles.Add(SockType.Purchase, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.Tech
                                 | AuthorizationRoles.SalesRestricted
                                 ,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //VENDOR NOTIFICATION
            //         
            roles.Add(SockType.VendorNotification, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.Tech
                                 | AuthorizationRoles.SalesRestricted
                                 ,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //PRODUCT
            //       
            roles.Add(SockType.Product, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.Tech
                                 | AuthorizationRoles.SalesRestricted
                                 ,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //GZCASE
            //  
            roles.Add(SockType.GZCase, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdmin
                         | AuthorizationRoles.Service
                         | AuthorizationRoles.Sales
                         | AuthorizationRoles.Accounting,
                ReadFullRecord = AuthorizationRoles.BizAdminRestricted
                                 | AuthorizationRoles.ServiceRestricted
                                 | AuthorizationRoles.Tech
                                 | AuthorizationRoles.SalesRestricted
                                 ,
                Select = AuthorizationRoles.All
            });



            ////////////////////////////////////////////////////////////////////
            #endregion all roles init


            #region output as JSON for client side

#if (DEBUG)
            //ONGOING VALIDATION TO CATCH MISMATCH WHEN NEW ROLES ADDED (wont' catch changes to existing unfortunately)    
            //################## HOW TO USE ##########
            //##############  Uncomment code block below, put a break on lastRoles, copy from the output in the LOG (good for javascript with quotes formatted that way) #######
            // #### NEED to separately take a copy and update "lastRoles" string here by copying from the variable watch for the "json" variable shown in the debugger because need the C# format escaped quotes string

            //GENERATE CLIENT COMPATIBLE JSON FROM ROLES OUTPUT TO DEBUG LOG
            //And seperately, set the JSON variable so can copy from debug variable "value" property for lastRoles here to compare



            /*       
                  string json = Newtonsoft.Json.JsonConvert.SerializeObject(roles, Newtonsoft.Json.Formatting.None);
                  System.Diagnostics.Debugger.Log(1, "JSONFRAGMENTFORCLIENT", "BizRoles.cs -> biz-role-rights.js Client roles JSON fragment:\n\n");
                  System.Diagnostics.Debugger.Log(1, "JSONFRAGMENTFORCLIENT", json + "\n\n");                                   
                  var lastRoles = "{\"Customer\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"CustomerNote\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"CustomerNotifySubscription\":{\"Change\":10,\"ReadFullRecord\":65797,\"Select\":131071},\"HeadOffice\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"Global\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":0},\"GlobalOps\":{\"Change\":16384,\"ReadFullRecord\":8192,\"Select\":0},\"User\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":131071},\"UserOptions\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":0},\"ServerState\":{\"Change\":16384,\"ReadFullRecord\":131071,\"Select\":0},\"LogFile\":{\"Change\":0,\"ReadFullRecord\":24576,\"Select\":0},\"Backup\":{\"Change\":16384,\"ReadFullRecord\":8195,\"Select\":0},\"FileAttachment\":{\"Change\":2,\"ReadFullRecord\":3,\"Select\":0},\"ServerJob\":{\"Change\":16384,\"ReadFullRecord\":8195,\"Select\":0},\"OpsNotificationSettings\":{\"Change\":16384,\"ReadFullRecord\":8195,\"Select\":0},\"ServerMetrics\":{\"Change\":16384,\"ReadFullRecord\":24576,\"Select\":0},\"Translation\":{\"Change\":2,\"ReadFullRecord\":1,\"Select\":131071},\"DataListSavedFilter\":{\"Change\":2,\"ReadFullRecord\":131071,\"Select\":0},\"FormUserOptions\":{\"Change\":131071,\"ReadFullRecord\":131071,\"Select\":0},\"FormCustom\":{\"Change\":2,\"ReadFullRecord\":131071,\"Select\":0},\"PickListTemplate\":{\"Change\":2,\"ReadFullRecord\":131071,\"Select\":0},\"BizMetrics\":{\"Change\":2,\"ReadFullRecord\":98369,\"Select\":0},\"Notification\":{\"Change\":131071,\"ReadFullRecord\":131071,\"Select\":0},\"NotifySubscription\":{\"Change\":131071,\"ReadFullRecord\":131071,\"Select\":0},\"Report\":{\"Change\":3,\"ReadFullRecord\":131071,\"Select\":131071},\"Memo\":{\"Change\":124927,\"ReadFullRecord\":124927,\"Select\":124927},\"Reminder\":{\"Change\":124927,\"ReadFullRecord\":124927,\"Select\":124927},\"Review\":{\"Change\":124927,\"ReadFullRecord\":124927,\"Select\":124927},\"Integration\":{\"Change\":49514,\"ReadFullRecord\":49514,\"Select\":49514},\"License\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"TrialLicenseRequest\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"SubscriptionServer\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"Purchase\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"Product\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071},\"GZCase\":{\"Change\":32842,\"ReadFullRecord\":65797,\"Select\":131071}}";
                  Dictionary<SockType, BizRoleSet> lastRolesDeserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<SockType, BizRoleSet>>(lastRoles);
                  if (lastRolesDeserialized.Count != roles.Count)
                  {

                      {
                          ((ILogger)Sockeye.Util.ApplicationLogging.CreateLogger("BizRoles.cs")).LogWarning("BizRoles::Constructor - roles were modified from last snapshot for client!!!");
                      }
                  }
      */


#endif
            #endregion




        }//end of constructor


        /// <summary>
        /// Get roleset for biz object
        /// </summary>
        /// <param name="forType"></param>
        /// <returns></returns>
        internal static BizRoleSet GetRoleSet(SockType forType)
        {
            if (roles.ContainsKey(forType))
            {
                return roles[forType];
            }
            else
            {
                return null;
            }
        }





    }//end of class


}//eons 

