using DbController;
using Tabletop.Core.Interfaces;
using Tabletop.Core.Models.Abstract;

namespace Tabletop.Core.Models
{
    public class Surface : LocalizationModelBase<SurfaceDescription>, IDbModel<int?>
    {
        [CompareField("surface_id")]
        public int SurfaceId { get; set; }

        [CompareField("image")]
        public byte[]? Image { get; set; }

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

        public int? GetIdentifier()
        {
            return SurfaceId > 0 ? SurfaceId : null;
        }

        public IEnumerable<Dictionary<string, object?>> GetLocalizedParameters()
        {
            foreach (var description in Description)
            {
                yield return new Dictionary<string, object?>
                {
                    { "SURFACE_ID", SurfaceId },
                    { "NAME", description.Name },
                    { "DESCRIPTION", description.Description }
                };
            }
        }

        public Dictionary<string, object?> GetParameters()
        {
            return new Dictionary<string, object?>
            {
                { "SURFACE_ID", SurfaceId },
                { "IMAGE", Image }
            };
        }
    }

    public class SurfaceDescription : ILocalizationHelper
    {
        [CompareField("surface_id")]
        public int SurfaceId { get; set; }

        [CompareField("code")]
        public string Code { get; set; } = string.Empty;

        [CompareField("name")]
        public string Name { get; set; } = string.Empty;

        [CompareField("description")]
        public string Description { get; set; } = string.Empty;
    }
}