use chrono::NaiveDate;
use service_kit::api_dto;
use serde_json::Value as JsonValue;
use uuid::Uuid;

// Companies API DTOs
#[api_dto]
pub struct CompanyProfileDto {
    pub symbol: String,
    pub name: String,
    pub industry: Option<String>,
    pub list_date: Option<NaiveDate>,
    pub additional_info: Option<JsonValue>,
    pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
}

// Market Data API DTOs
#[api_dto]
pub struct TimeSeriesFinancialDto {
    pub symbol: String,
    pub metric_name: String,
    pub period_date: NaiveDate,
    pub value: f64,
    pub source: Option<String>,
}

#[api_dto]
pub struct DailyMarketDataDto {
    pub symbol: String,
    pub trade_date: NaiveDate,
    pub open_price: Option<f64>,
    pub high_price: Option<f64>,
    pub low_price: Option<f64>,
    pub close_price: Option<f64>,
    pub volume: Option<i64>,
    pub pe: Option<f64>,
    pub pb: Option<f64>,
    pub total_mv: Option<f64>,
}

// Batch DTOs
#[api_dto]
pub struct TimeSeriesFinancialBatchDto {
    pub records: Vec<TimeSeriesFinancialDto>,
}

#[api_dto]
pub struct DailyMarketDataBatchDto {
    pub records: Vec<DailyMarketDataDto>,
}


// Analysis Results API DTOs (REMOVED)
// #[api_dto]
// pub struct NewAnalysisResult { ... }
// #[api_dto]
// pub struct AnalysisResultDto { ... }

// Workflow History DTOs (NEW)
#[api_dto]
pub struct WorkflowHistoryDto {
    pub request_id: Uuid,
    pub symbol: String,
    pub market: String,
    pub template_id: Option<String>,
    pub status: String,
    pub start_time: chrono::DateTime<chrono::Utc>,
    pub end_time: Option<chrono::DateTime<chrono::Utc>>,
    pub snapshot_data: JsonValue,
    pub created_at: chrono::DateTime<chrono::Utc>,
}

#[api_dto]
pub struct NewWorkflowHistory {
    pub request_id: Uuid,
    pub symbol: String,
    pub market: String,
    pub template_id: Option<String>,
    pub status: String,
    pub start_time: chrono::DateTime<chrono::Utc>,
    pub end_time: Option<chrono::DateTime<chrono::Utc>>,
    pub snapshot_data: JsonValue,
}

#[api_dto]
pub struct WorkflowHistorySummaryDto {
    pub request_id: Uuid,
    pub symbol: String,
    pub market: String,
    pub template_id: Option<String>,
    pub status: String,
    pub start_time: chrono::DateTime<chrono::Utc>,
    pub end_time: Option<chrono::DateTime<chrono::Utc>>,
}




// Realtime Quotes DTOs
#[api_dto]
pub struct RealtimeQuoteDto {
    pub symbol: String,
    pub market: String,
    pub ts: chrono::DateTime<chrono::Utc>,
    pub price: f64,
    pub open_price: Option<f64>,
    pub high_price: Option<f64>,
    pub low_price: Option<f64>,
    pub prev_close: Option<f64>,
    pub change: Option<f64>,
    pub change_percent: Option<f64>,
    pub volume: Option<i64>,
    pub source: Option<String>,
}

use crate::observability::ObservabilityTaskStatus;

#[api_dto]
pub struct ProviderStatusDto {
    pub last_updated: chrono::DateTime<chrono::Utc>,
    pub status: ObservabilityTaskStatus, 
    pub data_version: Option<String>,
}

// Provider Path Params
#[api_dto]
#[derive(utoipa::IntoParams)]
pub struct ProviderPathParams {
    pub symbol: String,
    pub provider_id: String,
}

// Session Data & Cache DTOs
#[api_dto]
pub struct SessionDataDto {
    pub request_id: Uuid,
    pub symbol: String,
    pub provider: String,
    pub data_type: String,
    pub data_payload: JsonValue,
    pub created_at: Option<chrono::DateTime<chrono::Utc>>,
}

#[api_dto]
pub struct ProviderCacheDto {
    pub cache_key: String,
    pub data_payload: JsonValue,
    pub expires_at: chrono::DateTime<chrono::Utc>,
    pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
}
