using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace AsbCloudDb.Model
{
    [Table("t_measure"), Comment("Таблица c данными для вкладки \'Последние данные\'")]
    public class Measure : IId
    {
        [Key]
        [Column("id")]
        public int Id { get; set; }

        [Column("id_well"), Comment("id скважины")]
        public int IdWell { get; set; }

        [Column("id_category"), Comment("id категории")]
        public int IdCategory { get; set; }

        [Column("timestamp", TypeName = "timestamp with time zone"), Comment("время добавления")]
        public DateTimeOffset Timestamp { get; set; }

        [Column("data", TypeName = "jsonb"), Comment("Данные таблицы последних данных")]
        public RawData Data { get; set; } = new ();

        [Column("is_deleted"), Comment("Пометка удаленным")]
        public bool IsDeleted { get; set; }

        [JsonIgnore]
        [ForeignKey(nameof(IdWell))]
        public virtual Well Well { get; set; } = null!;

        [JsonIgnore]
        [ForeignKey(nameof(IdCategory))]
        [InverseProperty(nameof(Model.MeasureCategory.Measures))]
        public virtual MeasureCategory Category { get; set; } = null!;
    }
}