using SQLite;
using System.Text.Json.Serialization;

namespace salesbook.Shared.Core.Entity;

[Table("ptb_pros_rif")]
public class PtbProsRif
{
    [PrimaryKey, Column("composite_key")] 
    public string CompositeKey { get; set; }

    private string? _codPpro;

    [Column("cod_ppro"), JsonPropertyName("codPpro"), Indexed(Name = "PtbProsRifPK", Order = 1, Unique = true)]
    public string? CodPpro
    {
        get => _codPpro;
        set
        {
            _codPpro = value;
            if (_codPpro != null && _idPersRif != null)
                UpdateCompositeKey();
        }
    }

    private int? _idPersRif;

    [Column("id_pers_rif"), JsonPropertyName("idPersRif"), Indexed(Name = "PtbProsRifPK", Order = 2, Unique = true)]
    public int? IdPersRif
    {
        get => _idPersRif;
        set
        {
            _idPersRif = value;
            if (_codPpro != null && _idPersRif != null)
                UpdateCompositeKey();
        }
    }

    [Column("persona_rif"), JsonPropertyName("personaRif")]
    public string PersonaRif { get; set; }

    [Column("e_mail"), JsonPropertyName("eMail")]
    public string EMail { get; set; }

    [Column("fax"), JsonPropertyName("fax")]
    public string Fax { get; set; }

    [Column("mansione"), JsonPropertyName("mansione")]
    public string Mansione { get; set; }

    [Column("num_cellulare"), JsonPropertyName("numCellulare")]
    public string NumCellulare { get; set; }

    [Column("telefono"), JsonPropertyName("telefono")]
    public string Telefono { get; set; }

    private void UpdateCompositeKey() => 
        CompositeKey = $"{CodPpro}::{IdPersRif}";
}