namespace Berufsschule_HAM.Models;

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

public class AssetModel
{
    public required string Cn { get; set; }
    public string? SerialNumber { get; set; }
    public AssetDescription? Description { get; set; }
    public string? Location { get; set; }
    public string? Owner { get; set; }
    public string? Name { get; set; }

    public AssetModel(Dictionary<string, string> ldapData)
    {
        Cn = ldapData.GetValueOrDefault("cn") ?? throw new AssetModelConfigurationException();
        SerialNumber = ldapData.GetValueOrDefault("serialNumber");
        Location = ldapData.GetValueOrDefault("l");
        Owner = ldapData.GetValueOrDefault("owner");
        Name = ldapData.GetValueOrDefault("name");
        string? descriptionValue = ldapData.GetValueOrDefault("description");
        if (descriptionValue is null)
        {
            Description = new();
        }
        else
        {
            Description = JsonSerializer.Deserialize<AssetDescription>(descriptionValue) ?? new();
        }
    }
}

public class AssetDescription
{
    public string? Type { get; set; }
    public AssetPurchase? Purchase { get; set; }
}

public class AssetPurchase
{
    public string? PurchaseDate { get; set; }
    public string? PurchaseValue { get; set; }
    public string? PurchasedAt { get; set; }
    public string? PurchasedBy { get; set; }
}

public class AssetsTableViewModel
{
    public string? UserUID { get; set; }
    public required string AssetCn { get; set; }
    public string? AssetName { get; set; }
    public string? LocationName { get; set; }
}