using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using detect.gui.Commons;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;

namespace detect.gui.Models.Entities;

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

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

    [StringLength(255), Comment("设备序列号")] 
    [JsonProperty(PropertyName = "deviceSn")]
    [Column("device_sn")]
    public string? DeviceSn { get; set; }
    
    [StringLength(20), Comment("设备IP地址")]
    [RegularExpression(RegexHelper.IpV4, ErrorMessage = "IpV4: {0}格式非法")]
    [JsonProperty(PropertyName = "deviceIp")]
    [Column("device_ip")]
    public string? DeviceIp { 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; }
}