using System;
using System.Collections.Generic;
using Kreta.Naplo.Infrastructure;
namespace Kreta.Naplo.Domain
{
///
/// Service contect
///
public class ServiceContext
{
///
/// Institute code
///
public string InstituteCode { get; }
///
/// User identitier
///
public int UserId { get; }
///
/// User roles
///
public IEnumerable UserRoles { get; }
///
/// Base url
///
public string BaseUrl { get; }
public int SchoolYearId { get; }
///
/// Api key
///
public string ApiKey { get; }
///
/// User agent
///
public string UserAgent { get; }
///
/// Constuctor
///
/// Institute code
/// User Id
/// User roles
/// Base url
/// Api key
/// User Agent
public ServiceContext(string instituteCode, int userId, IEnumerable userRoles, string baseUrl, string apiKey, string userAgent, int schoolYearId)
{
if (string.IsNullOrWhiteSpace(instituteCode))
{
throw new ArgumentException($"{nameof(InstituteCode)} cannot be null or white space");
}
this.InstituteCode = instituteCode;
if (userId < Constants.MinimumPrimaryKeyValue)
{
throw new ArgumentException($"{nameof(userId)} must be greater or equal than {Constants.MinimumPrimaryKeyValue}");
}
if (schoolYearId < Constants.MinimumPrimaryKeyValue)
{
throw new ArgumentException($"{nameof(schoolYearId)} must be greater or equal than {Constants.MinimumPrimaryKeyValue}");
}
this.SchoolYearId = schoolYearId;
this.UserId = userId;
this.UserRoles = userRoles ?? throw new ArgumentNullException(nameof(userRoles));
if (string.IsNullOrWhiteSpace(baseUrl))
{
throw new ArgumentException($"{nameof(baseUrl)} cannot be null or white space");
}
this.BaseUrl = baseUrl;
if (string.IsNullOrWhiteSpace(apiKey))
{
throw new ArgumentException($"{nameof(apiKey)} cannot be null or white space");
}
this.ApiKey = apiKey;
UserAgent = userAgent ?? throw new ArgumentNullException(nameof(userAgent));
}
}
}