using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Avalonia.Collections;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;

namespace detect.gui.Models.Entities;

[Table("dat_authority")]
[Index(nameof(Name), IsUnique = true)]
[Index(nameof(ParentId), IsUnique = false)]
public class AuthorityEntity
{
    [Key]
    [JsonProperty(PropertyName = "id")]
    [Column("id")]
    public long? Id { get; set; }

    [StringLength(255), Comment("名称")] 
    [JsonProperty(PropertyName = "name")]
    [Column("name")]
    public string? Name { get; set; }

    [DefaultValue(0)] 
    [JsonProperty(PropertyName = "parentId")]
    [Column("parent_id")]
    public long? ParentId { get; set; }

    [Comment("创建时间")] 
    [JsonProperty(PropertyName = "createTime")]
    [Column("create_time")]
    public DateTime? CreateTime { get; set; }

    [Comment("更新时间")] 
    [JsonProperty(PropertyName = "updateTime")]
    [Column("update_time")]
    public DateTime? UpdateTime { get; set; }

    [NotMapped]
    [JsonIgnore]
    public AvaloniaList<AuthorityEntity>? Children { get; set; }
}