using System.ComponentModel.DataAnnotations;
using DataModel.Database.Common;

namespace DataModel.Database;

public sealed class Setting
{
    [Key]
    public int Id { get; set; }

    public Guid UniqueId { get; set; } = Guid.NewGuid();

    public string Code { get; set; } = string.Empty;

    public string TextValue { get; set; } = string.Empty;

    public bool BoolValue { get; set; }

    public int IntegerValue { get; set; }

    public Guid GuidValue { get; set; }

    internal DataContext.JsonUniqueId JsonUniqueId => new(this.Code, this.UniqueId, "Set");
    
    internal DataContext.JsonSetting ToJsonSetting() => new()
    {
        UniqueId = this.JsonUniqueId,
        Code = this.Code,
        BoolValue = this.BoolValue,
        GuidValue = this.GuidValue,
        IntegerValue = this.IntegerValue,
        TextValue = this.TextValue,
    };
    
    internal static Setting FromJsonSetting(DataContext.JsonSetting jsonSetting) => new()
    {
        UniqueId = jsonSetting.UniqueId.UniqueId,
        Code = jsonSetting.Code,
        BoolValue = jsonSetting.BoolValue,
        GuidValue = jsonSetting.GuidValue,
        IntegerValue = jsonSetting.IntegerValue,
        TextValue = jsonSetting.TextValue,
    };
}