using IRaCIS.Core.Application.Auth;
using IRaCIS.Core.Domain.Share;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace IRaCIS.Core.API
{
    public static class AuthorizationPolicySetup
    {

        public static void AddAuthorizationPolicySetup(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddAuthorization(options =>
            {
                //影像质控策略  只允许 IC  IQC进行操作
                options.AddPolicy(IRaCISPolicy.CRC_IQC, policyBuilder =>
                {
                    policyBuilder.RequireClaim("userTypeEnumInt", ((int)UserTypeEnum.ClinicalResearchCoordinator).ToString(), ((int)UserTypeEnum.IQC).ToString());
                });

                //一致性核查策略  只允许 IC  PM APM 进行操作
                options.AddPolicy(IRaCISPolicy.PM_APM_CRC, policyBuilder =>
                {
                    policyBuilder.RequireClaim("userTypeEnumInt", ((int)UserTypeEnum.ProjectManager).ToString(), ((int)UserTypeEnum.ClinicalResearchCoordinator).ToString(), ((int)UserTypeEnum.APM).ToString());
                });


                options.AddPolicy(IRaCISPolicy.PM_APM, policyBuilder =>
                {
                    policyBuilder.RequireClaim("userTypeEnumInt", ((int)UserTypeEnum.ProjectManager).ToString(), ((int)UserTypeEnum.APM).ToString());
                });

                options.AddPolicy(IRaCISPolicy.PM_IQC, policyBuilder =>
                {
                    policyBuilder.RequireClaim("userTypeEnumInt", ((int)UserTypeEnum.ProjectManager).ToString(), ((int)UserTypeEnum.IQC).ToString());
                });
       

                options.AddPolicy(IRaCISPolicy.PM, policyBuilder =>
                {
                    policyBuilder.RequireClaim("userTypeEnumInt", ((int)UserTypeEnum.ProjectManager).ToString());
                });


                options.AddPolicy(IRaCISPolicy.IQC, policyBuilder =>
                {
                    policyBuilder.RequireClaim("userTypeEnumInt", ((int)UserTypeEnum.IQC).ToString());
                });


                options.AddPolicy(IRaCISPolicy.PM_APM_CRC_QC, policyBuilder =>
                {
                    policyBuilder.RequireClaim("userTypeEnumInt", ((int)UserTypeEnum.ProjectManager).ToString(),((int)UserTypeEnum.ClinicalResearchCoordinator).ToString(), ((int)UserTypeEnum.APM).ToString(), ((int)UserTypeEnum.IQC).ToString());
                });

                options.AddPolicy(IRaCISPolicy.SPM_CPM, policyBuilder =>
                {
                    policyBuilder.RequireClaim("userTypeEnumInt", ((int)UserTypeEnum.SPM).ToString(), ((int)UserTypeEnum.CPM).ToString());
                });

                options.AddPolicy(IRaCISPolicy.PM_APM_SPM_CPM, policyBuilder =>
                {
                    policyBuilder.RequireClaim("userTypeEnumInt", ((int)UserTypeEnum.ProjectManager).ToString(), ((int)UserTypeEnum.APM).ToString(),((int)UserTypeEnum.SPM).ToString(), ((int)UserTypeEnum.CPM).ToString());
                });

                options.AddPolicy(IRaCISPolicy.PM_APM_SPM_CPM_SMM_CMM, policyBuilder =>
                {
                    policyBuilder.RequireClaim("userTypeEnumInt", ((int)UserTypeEnum.ProjectManager).ToString(), ((int)UserTypeEnum.APM).ToString(), ((int)UserTypeEnum.SPM).ToString(), 
                        ((int)UserTypeEnum.CPM).ToString(), ((int)UserTypeEnum.SMM).ToString(), ((int)UserTypeEnum.CMM).ToString());
                });


                

            });
        }


      

    }
}
