using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using SteUp.Shared.Core.Dto;

namespace SteUp.Shared.Core.Entities;

public class Scheda : EntityBase<Scheda>
{
    [Key]
    public int Id { get; set; }
    public string? ActivityId { get; set; }
    public string? CodJfas { get; set; }
    
    [Required]
    public string CodMdep { get; set; } = string.Empty;
    public DateTime Data { get; set; }
    [Required]
    public string Rilevatore { get; set; } = string.Empty;
    public Ispezione? Ispezione { get; set; }
    
    public List<SchedaArticolo> Articoli { get; set; } = [];
    public List<string>? ImageNames { get; set; }
    
    public string? DescrizioneReparto { get; set; }
    public string? ActivityTypeId { get; set; }
    public string? Note { get; set; }
    public string? Responsabile { get; set; }
    public int Scadenza { get; set; }
    
    [NotMapped]
    public JtbFasiDto? Reparto
    {
        get
        {
            if (field == null && CodJfas != null)
            {
                field = new JtbFasiDto
                {
                    CodJfas = CodJfas,
                    Descrizione = DescrizioneReparto
                };
            }

            return field;
        }
        set
        {
            field = value;
            if (value == null) return;

            CodJfas = value.CodJfas;
            DescrizioneReparto = value.Descrizione;
        }
    }
}