
using dodohold.core;
using System.Text.Json;

namespace molilian.core
{
    [Table("aliyun_ecs")]
    public class AliyunEcsDTO
    {
        [Key]
        public int id { get; set; }

        public int account_id { get; set; }

        public string name { get; set; } = string.Empty;
        public string description { get; set; } = string.Empty;
        public DateTime create_time { get; set; } = DateTime.Now;
        public DateTime last_time { get; set; } = DateTime.Now;


        public string instance_id { get; set; } = string.Empty;
        public string instance_name { get; set; } = string.Empty;
        public string host_name { get; set; } = string.Empty;
        public string os_name { get; set; } = string.Empty;
        public string region_id { get; set; } = string.Empty;
        public string instance_type { get; set; } = string.Empty;
        public int cpu { get; set; } = 0;
        public decimal memory { get; set; } = 0;
        public DateTime expired_time { get; set; } = DateTime.MinValue;
        public DateTime creation_time { get; set; } = DateTime.MinValue;


        [Column("address_ips")]
        public string AddressIpsJson
        {
            get => JsonSerializer.Serialize(AddressIps);
            set => AddressIps = string.IsNullOrEmpty(value)
                ? new List<AddressIpDTO>()
                : JsonSerializer.Deserialize<List<AddressIpDTO>>(value);
        }

        [NotMapped] // 这个属性不会映射到数据库
        public List<AddressIpDTO> AddressIps { get; set; } = [];
    }


    public class AddressIpDTO
    {
        public string networkInterfaceId { get; set; } = string.Empty;
        public string privateIp { get; set; } = string.Empty;
        public string publicIp { get; set; } = string.Empty;
    }

}
