using System.Text.Json;
using Berufsschule_HAM.Exceptions;

namespace Berufsschule_HAM.Models;

public class MigrationModel
{
    public int Version { get; set; }
    public MigrationModel(Dictionary<string, string> ldapData)
    {
        string? description = ldapData.GetValueOrDefault("description");
        if (description is null)
        {
            Version = 0;
        }
        else
        {
            MigrationDescriptionModel? descriptionModel = JsonSerializer.Deserialize<MigrationDescriptionModel>(description)
                ?? throw new InvalidMigrationDescriptionModel();
            Version = descriptionModel.Version;
        }
    }
}

public class MigrationDescriptionModel
{
    public required int Version { get; set; }
}