using Manager.DTOs;
using ManagerService.Data.SubSection;
using ManagerService.DTOs;
using ManagerService.Services;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace ManagerService.Data
{
///
/// Defines the link between an application instance and a configuration,
/// allowing apps to use one or multiple configurations.
///
public class ApplicationInstance
{
[Key]
public string Id { get; set; }
[Required]
public string InstanceId { get; set; }
[Required]
public AppType AppType { get; set; }
public List Configurations { get; set; }
public string MainImageId { get; set; } // Specific Mobile et web(?)
public string MainImageUrl { get; set; } // Specific Mobile et web(?)
public string LoaderImageId { get; set; } // Specific Mobile et web
public string LoaderImageUrl { get; set; } // Specific Mobile et web
public string PrimaryColor { get; set; } // Specific Mobile et web
public string SecondaryColor { get; set; } // Specific Mobile et web
public LayoutMainPageType LayoutMainPage { get; set; } = LayoutMainPageType.MasonryGrid; // Specific Mobile et web
public List Languages { get; set; } // All app must support languages, if not, client's problem
public string? SectionEventId { get; set; } // Specific Mobile et web(?)
[ForeignKey("SectionEventId")]
public SectionEvent? SectionEvent { get; set; } // => To Display in large a event with countdown (in mobile app).
public ApplicationInstanceDTO ToDTO(MyInfoMateDbContext myInfoMateDbContext)
{
SectionEventDTO sectionEventDTO = null;
if (SectionEventId != null)
{
SectionEvent = myInfoMateDbContext.Sections.OfType().FirstOrDefault(s => s.Id == SectionEventId);
sectionEventDTO = SectionEvent != null ? SectionFactory.ToDTO(SectionEvent) as SectionEventDTO : null;
}
return new ApplicationInstanceDTO()
{
id = Id,
instanceId = InstanceId,
appType = AppType,
configurations = Configurations,
mainImageId = MainImageId,
mainImageUrl = MainImageUrl,
loaderImageId = LoaderImageId,
loaderImageUrl = LoaderImageUrl,
primaryColor = PrimaryColor,
secondaryColor = SecondaryColor,
layoutMainPage = LayoutMainPage,
languages = Languages,
sectionEventId = SectionEventId,
sectionEventDTO = sectionEventDTO
};
}
public ApplicationInstance FromDTO(ApplicationInstanceDTO dto)
{
InstanceId = dto.instanceId;
AppType = dto.appType;
MainImageId = dto.mainImageId;
MainImageUrl = dto.mainImageUrl;
LoaderImageId = dto.loaderImageId;
LoaderImageUrl = dto.loaderImageUrl;
PrimaryColor = dto.primaryColor;
SecondaryColor = dto.secondaryColor;
LayoutMainPage = dto.layoutMainPage;
Languages = dto.languages;
Configurations = dto.configurations;
SectionEventId = dto.sectionEventId;
return this;
}
}
public enum AppType
{
Mobile,
Tablet,
Web,
VR
}
public enum LayoutMainPageType
{
SimpleGrid,
MasonryGrid
}
}