using System.Text.Json.Serialization;

namespace Hc900Crawler.Core.Application.DTOs;

// 이 프로젝트의 기본 JSON 직렬화는 PascalCase 패스스루다(기존 컨트롤러는 익명객체로 직접 camelCase 명명).
// 트렌드 DTO는 프론트(camelCase) 계약에 맞추기 위해 [JsonPropertyName]으로 camelCase 고정.
// (입력 바인딩은 MVC 기본 대소문자 무시라 무관, 출력 일관성 목적)

/// <summary>트렌드 그룹 멤버 — 태그 + 색상 + Y축(좌/우)</summary>
public class TrendMemberDto
{
    [JsonPropertyName("tag")]   public string Tag   { get; set; } = "";
    [JsonPropertyName("color")] public string Color { get; set; } = "";   // #rrggbb
    [JsonPropertyName("axis")]  public string Axis  { get; set; } = "left"; // left | right
}

/// <summary>트렌드 그룹 (멤버는 JSONB 저장)</summary>
public class TrendGroupDto
{
    [JsonPropertyName("id")]          public int      Id          { get; set; }
    [JsonPropertyName("name")]        public string   Name        { get; set; } = "";
    [JsonPropertyName("description")] public string?  Description  { get; set; }
    [JsonPropertyName("members")]     public List<TrendMemberDto> Members { get; set; } = new();
    [JsonPropertyName("createdAt")]   public DateTime CreatedAt   { get; set; }
    [JsonPropertyName("updatedAt")]   public DateTime UpdatedAt   { get; set; }
}

/// <summary>그룹 생성/수정 요청</summary>
public class TrendGroupUpsertDto
{
    [JsonPropertyName("name")]        public string   Name        { get; set; } = "";
    [JsonPropertyName("description")] public string?  Description  { get; set; }
    [JsonPropertyName("members")]     public List<TrendMemberDto> Members { get; set; } = new();
}

/// <summary>아날로그 포인트 (그룹 빌더용 — 숫자 livevalue 한정)</summary>
public class AnalogPointDto
{
    [JsonPropertyName("tagName")]     public string   TagName     { get; set; } = "";
    [JsonPropertyName("baseTag")]     public string   BaseTag     { get; set; } = "";
    [JsonPropertyName("value")]       public double?  Value       { get; set; }
    [JsonPropertyName("timestamp")]   public DateTime Timestamp   { get; set; }
    [JsonPropertyName("unit")]        public string?  Unit        { get; set; }
    [JsonPropertyName("euLo")]        public double?  EuLo        { get; set; }
    [JsonPropertyName("euHi")]        public double?  EuHi        { get; set; }
    [JsonPropertyName("description")] public string?  Description  { get; set; }
    [JsonPropertyName("area")]        public string?  Area        { get; set; }
}

/// <summary>실시간 tail 포인트 (현재값)</summary>
public class TrendLivePointDto
{
    [JsonPropertyName("tag")]   public string   Tag   { get; set; } = "";
    [JsonPropertyName("value")] public double?  Value { get; set; }
    [JsonPropertyName("ts")]    public DateTime Ts    { get; set; }
}

/// <summary>알람 한계선 (HI/LO/SP)</summary>
public class TrendLimitDto
{
    [JsonPropertyName("tag")]   public string   Tag   { get; set; } = "";
    [JsonPropertyName("hi")]    public double?  Hi    { get; set; }
    [JsonPropertyName("lo")]    public double?  Lo    { get; set; }
    [JsonPropertyName("sp")]    public double?  Sp    { get; set; }
    [JsonPropertyName("unit")]  public string?  Unit  { get; set; }
}

/// <summary>운전상태 밴드 (RUN/TRIP 구간)</summary>
public class TrendBandDto
{
    [JsonPropertyName("tag")]   public string   Tag   { get; set; } = "";
    [JsonPropertyName("t0")]    public DateTime T0    { get; set; }
    [JsonPropertyName("t1")]    public DateTime T1    { get; set; }
    [JsonPropertyName("state")] public string   State { get; set; } = "";
}
