using Postgrest.Attributes;
using Postgrest.Models;
using UnityEngine;
using Newtonsoft.Json;
using System;

namespace GhostSystem
{
    [Table("object_positions")]
    public class FrameModel : BaseModel
    {

        [Column("user_id")]
        public string UserId { get; set; }

        [Column("scene_id")]
        public string SceneId { get; set; }

        [Column("object_id")]
        public string ObjectId { get; set; }

        [Column("timestamp")]
        public string Timestamp { get; set; } // ISO 8601 string

        [Column("position")]
        public string PositionJson { get; set; } // stored as JSONB

        [Column("rotation")]
        public string RotationJson { get; set; } // stored as JSONB

        [JsonIgnore]
        public DateTime TimestampParsed => DateTime.Parse(Timestamp).ToUniversalTime();

        [JsonIgnore]
        public Vector3 Position => JsonConvert.DeserializeObject<Vector3Serializable>(PositionJson).ToVector3();
        [JsonIgnore]
        public Quaternion Rotation => JsonConvert.DeserializeObject<QuaternionSerializable>(RotationJson).ToQuaternion();

    }
}

