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

namespace salesbook.Shared.Core.Entity;

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

    private string? _activityTypeId;

    [Column("activity_type_id"), JsonPropertyName("activityTypeId"), Indexed(Name = "ActivityTypePK", Order = 1, Unique = true)]
    public string? ActivityTypeId
    {
        get => _activityTypeId;
        set
        {
            _activityTypeId = value;
            if (_activityTypeId != null && _flagTipologia != null)
                UpdateCompositeKey();
        }
    }

    private string? _flagTipologia;

    [Column("flag_tipologia"), JsonPropertyName("flagTipologia"), Indexed(Name = "ActivityTypePK", Order = 2, Unique = true)]
    public string? FlagTipologia
    {
        get => _flagTipologia;
        set
        {
            _flagTipologia = value;
            if (_activityTypeId != null && _flagTipologia != null)
                UpdateCompositeKey();
        }
    }

    [Column("estimated_duration"), JsonPropertyName("estimatedDuration")]
    public double? EstimatedDuration { get; set; } = 0;

    [Column("link_gest"), JsonPropertyName("linkGest")]
    public string? LinkGest { get; set; } 

    [Column("cod_jfas"), JsonPropertyName("codJfas")]
    public string? CodJfas { get; set; }

    [Column("user_name"), JsonPropertyName("userName")]
    public string? UserName { get; set; }

    [Column("flag_sal"), JsonPropertyName("flagSal")]
    public string FlagSal { get; set; } = "N";

    [Column("flag_set_alarm"), JsonPropertyName("flagSetAlarm")]
    public string FlagSetAlarm { get; set; } = "N";

    [Column("flag_attiva"), JsonPropertyName("flagAttiva")]
    public string FlagAttiva { get; set; } = "S";

    [Column("flag_generate_mov"), JsonPropertyName("flagGenerateMov")]
    public string FlagGenerateMov { get; set; } = "S";

    [Column("flag_view_calendar"), JsonPropertyName("flagViewCalendar")]
    public bool FlagViewCalendar { get; set; }

    private void UpdateCompositeKey() =>
        CompositeKey = $"{ActivityTypeId}::{FlagTipologia}";
}