namespace TravelAgencyWinForms.Models;

public sealed class EntityConfig
{
    public string Title { get; init; } = string.Empty;
    public string TableName { get; init; } = string.Empty;
    public string? ViewName { get; init; }
    public string OrderBy { get; init; } = string.Empty;
    public bool ReadOnly { get; init; }
    public bool RestrictByCurrentEmployee { get; init; }
    public string? RestrictColumn { get; init; }
    public List<FieldConfig> Fields { get; init; } = new();

    public IEnumerable<FieldConfig> KeyFields => Fields.Where(f => f.IsKey);
    public IEnumerable<FieldConfig> GridFields => Fields.Where(f => f.ShowInGrid);
    public IEnumerable<FieldConfig> EditableFields => Fields.Where(f => !(f.IsKey && f.AutoIdentity));

    public string SourceName => ViewName ?? TableName;
}
