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

namespace AyaNova.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<AyaType, BizRoleSet> roles = new Dictionary<AyaType, 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


            //TODO: BIZ objects, fine tune this stuff, best guess first pass here
            //I'm wondering about seperate bizroles for workorderitem as well as workorder
            //like, is that really useful or not
            //controller could just check rights to workorder
            //but then I'm wondering if some items under workorder might have seperate roles...
            //maybe it's workorder by default unless something needs an override

            ////////////////////////////////////////////////////////////
            //CUSTOMER
            //            
            roles.Add(AyaType.Customer, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //Contract
            //            
            roles.Add(AyaType.Contract, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //HeadOffice
            //            
            roles.Add(AyaType.HeadOffice, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //LoanUnit
            //            
            roles.Add(AyaType.LoanUnit, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //Part
            //            
            roles.Add(AyaType.Part, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //PM
            //            
            roles.Add(AyaType.PM, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //PMItem
            //            
            roles.Add(AyaType.PMItem, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //PMTemplate
            //            
            roles.Add(AyaType.PMTemplate, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //PMTemplateItem
            //            
            roles.Add(AyaType.PMTemplateItem, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //Project
            //            
            roles.Add(AyaType.Project, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //PurchaseOrder
            //            
            roles.Add(AyaType.PurchaseOrder, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //Quote
            //            
            roles.Add(AyaType.Quote, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //QuoteItem
            //            
            roles.Add(AyaType.QuoteItem, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //QuoteTemplate
            //            
            roles.Add(AyaType.QuoteTemplate, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //QuoteTemplateItem
            //            
            roles.Add(AyaType.QuoteTemplateItem, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //Unit
            //            
            roles.Add(AyaType.Unit, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //UnitModel
            //            
            roles.Add(AyaType.UnitModel, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //Vendor
            //            
            roles.Add(AyaType.Vendor, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });


            ////////////////////////////////////////////////////////////
            //WorkOrder
            //            
            roles.Add(AyaType.WorkOrder, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            roles.Add(AyaType.WorkOrderItem, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            roles.Add(AyaType.WorkOrderItemExpense, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            roles.Add(AyaType.WorkOrderItemLabor, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            roles.Add(AyaType.WorkOrderItemLoan, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            roles.Add(AyaType.WorkOrderItemPart, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            roles.Add(AyaType.WorkOrderItemPartRequest, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            roles.Add(AyaType.WorkOrderItemScheduledUser, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            roles.Add(AyaType.WorkOrderItemTask, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            roles.Add(AyaType.WorkOrderItemTravel, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            roles.Add(AyaType.WorkOrderItemUnit, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });
            //---


            ////////////////////////////////////////////////////////////
            //WorkOrderTemplate
            //            
            roles.Add(AyaType.WorkOrderTemplate, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });

            ////////////////////////////////////////////////////////////
            //WorkOrderTemplateItem
            //            
            roles.Add(AyaType.WorkOrderTemplateItem, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.SalesFull | AuthorizationRoles.TechFull | AuthorizationRoles.AccountingFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.DispatchLimited | AuthorizationRoles.SalesLimited | AuthorizationRoles.TechLimited,
                Select = AuthorizationRoles.All
            });




            ////////////////////////////////////////////////////////////
            //GLOBAL BIZ SETTINGS
            //
            roles.Add(AyaType.Global, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited
            });


            ////////////////////////////////////////////////////////////
            //GLOBAL OPS SETTINGS
            // 
            roles.Add(AyaType.GlobalOps, new BizRoleSet()
            {
                Change = AuthorizationRoles.OpsAdminFull,
                ReadFullRecord = AuthorizationRoles.OpsAdminLimited
            });


            ////////////////////////////////////////////////////////////
            //USER
            //            
            roles.Add(AyaType.User, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited,
                Select = AuthorizationRoles.All
            });

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



            ////////////////////////////////////////////////////////////
            //WIDGET
            //
            roles.Add(AyaType.Widget, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.InventoryFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.InventoryLimited,
                Select = AuthorizationRoles.All
            });

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


            ////////////////////////////////////////////////////////////
            //LICENSE
            //
            roles.Add(AyaType.License, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.OpsAdminLimited
            });

            ////////////////////////////////////////////////////////////
            //TRIALSEEDER
            //
            roles.Add(AyaType.TrialSeeder, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.OpsAdminLimited
            });

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


            ////////////////////////////////////////////////////////////
            //BACKUP
            //Only opsfull can change Backup
            //ops and biz admin can view Backup        
            roles.Add(AyaType.Backup, new BizRoleSet()
            {
                Change = AuthorizationRoles.OpsAdminFull,
                ReadFullRecord = AuthorizationRoles.OpsAdminLimited | AuthorizationRoles.BizAdminFull | AuthorizationRoles.BizAdminLimited
            });


            ////////////////////////////////////////////////////////////
            //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 bulk 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(AyaType.FileAttachment, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull,//Need full rights only here because this is the rights checked for bulk delete etc so it's simpler than checking all the parent object rights if you know they already have all rights
                ReadFullRecord = AuthorizationRoles.BizAdminFull | AuthorizationRoles.BizAdminLimited
            });


            ////////////////////////////////////////////////////////////
            //OPERATIONS / JOBS
            //Only opsfull can change operations
            //ops and biz admin can view operations        
            roles.Add(AyaType.ServerJob, new BizRoleSet()
            {
                Change = AuthorizationRoles.OpsAdminFull,
                ReadFullRecord = AuthorizationRoles.OpsAdminLimited | AuthorizationRoles.BizAdminFull | AuthorizationRoles.BizAdminLimited
            });

            ////////////////////////////////////////////////////////////
            //OPERATIONS / Notification settings
            //Only opsfull can change operations
            //ops and biz admin can view operations        
            roles.Add(AyaType.OpsNotificationSettings, new BizRoleSet()
            {
                Change = AuthorizationRoles.OpsAdminFull,
                ReadFullRecord = AuthorizationRoles.OpsAdminLimited | AuthorizationRoles.BizAdminFull | AuthorizationRoles.BizAdminLimited
            });


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


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


            ////////////////////////////////////////////////////////////
            //DATALISTFILTER
            //
            roles.Add(AyaType.DataListView, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull,
                ReadFullRecord = AuthorizationRoles.All
            });



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

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

            ////////////////////////////////////////////////////////////
            //BIZMETRICS
            //            
            roles.Add(AyaType.BizMetrics, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull,
                ReadFullRecord = AuthorizationRoles.BizAdminLimited |
                AuthorizationRoles.SalesFull |
                AuthorizationRoles.SalesLimited |
                AuthorizationRoles.AccountingFull
            });

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

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

            ////////////////////////////////////////////////////////////
            //REPORT
            //            
            roles.Add(AyaType.Report, new BizRoleSet()
            {
                Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.BizAdminLimited,
                ReadFullRecord = AuthorizationRoles.All,
                Select = AuthorizationRoles.All
            });

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


            #region output as JSON for client side

#if (DEBUG)

            //################## HOW TO USE ##########
            //##############  Uncomment SerializeObject and two debugger lines, 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:");
            // System.Diagnostics.Debugger.Log(1, "JSONFRAGMENTFORCLIENT", json);

            //ONGOING VALIDATION TO CATCH MISMATCH WHEN NEW ROLES ADDED (wont' catch changes to existing unfortunately)                                   
            var lastRoles = "{\"Customer\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"Contract\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"HeadOffice\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"LoanUnit\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"Part\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"PM\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"PMItem\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"PMTemplate\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"PMTemplateItem\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"Project\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"PurchaseOrder\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"Quote\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"QuoteItem\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"QuoteTemplate\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"QuoteTemplateItem\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"Unit\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"UnitModel\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"Vendor\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrder\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderItem\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderItemExpense\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderItemLabor\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderItemLoan\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderItemPart\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderItemPartRequest\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderItemScheduledUser\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderItemTask\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderItemTravel\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderItemUnit\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderTemplate\":{\"Change\":33098,\"ReadFullRecord\":65669,\"Select\":131071},\"WorkOrderTemplateItem\":{\"Change\":33098,\"ReadFullRecord\":65669,\"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},\"Widget\":{\"Change\":34,\"ReadFullRecord\":17,\"Select\":131071},\"ServerState\":{\"Change\":16384,\"ReadFullRecord\":131071,\"Select\":0},\"License\":{\"Change\":16386,\"ReadFullRecord\":8193,\"Select\":0},\"TrialSeeder\":{\"Change\":16386,\"ReadFullRecord\":8193,\"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\":16386,\"ReadFullRecord\":131071,\"Select\":0},\"DataListView\":{\"Change\":2,\"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}}";

            Dictionary<AyaType, BizRoleSet> lastRolesDeserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<AyaType, BizRoleSet>>(lastRoles);
            if (lastRolesDeserialized.Count != roles.Count)
            {
                //throw new System.ArgumentException("BizRoles::Constructor - roles were modified from last snapshot for client!!!");
                // log =
                {
                    ((ILogger)AyaNova.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(AyaType forType)
        {
            if (roles.ContainsKey(forType))
            {
                return roles[forType];
            }
            else
            {
                return null;
            }
        }




    }//end of class


}//eons 

