from datetime import datetime
from typing import Optional, Dict, Any, List
from pydantic import BaseModel, Field


class AnalyticsQueryParams(BaseModel):
    """分析查询参数"""
    from_date: Optional[datetime] = Field(None, description="开始日期")
    to_date: Optional[datetime] = Field(None, description="结束日期")
    city: Optional[str] = Field(None, description="城市筛选")
    company_name: Optional[str] = Field(None, description="公司名称筛选")
    position_name: Optional[str] = Field(None, description="职位名称筛选")
    industry: Optional[str] = Field(None, description="行业筛选")
    experience_required: Optional[str] = Field(None, description="经验要求筛选")
    limit: int = Field(10, ge=1, le=100, description="返回结果数量限制")


class SalaryStatistics(BaseModel):
    """薪资统计信息"""
    avg_salary_min: float = Field(description="最低薪资平均值")
    avg_salary_max: float = Field(description="最高薪资平均值")
    min_salary: float = Field(description="最低薪资")
    max_salary: float = Field(description="最高薪资")
    total_jobs: int = Field(description="有薪资信息的职位总数")


class JobStatisticsResponse(BaseModel):
    """职位统计响应"""
    total_jobs: int = Field(description="职位总数")
    period: Dict[str, Optional[str]] = Field(description="统计时间段")


class CategoryCount(BaseModel):
    """分类统计"""
    category: str = Field(description="分类名称")
    job_count: int = Field(description="职位数量")


class TopCompaniesResponse(BaseModel):
    """热门公司响应"""
    companies: List[CategoryCount] = Field(description="公司列表")
    total_count: int = Field(description="总数")


class TopPositionsResponse(BaseModel):
    """热门职位响应"""
    positions: List[CategoryCount] = Field(description="职位列表")
    total_count: int = Field(description="总数")


class CityDistributionResponse(BaseModel):
    """城市分布响应"""
    cities: List[CategoryCount] = Field(description="城市列表")
    total_count: int = Field(description="总数")


class IndustryDistributionResponse(BaseModel):
    """行业分布响应"""
    industries: List[CategoryCount] = Field(description="行业列表")
    total_count: int = Field(description="总数")


class ExperienceDistributionResponse(BaseModel):
    """经验要求分布响应"""
    experience_levels: List[CategoryCount] = Field(description="经验要求列表")
    total_count: int = Field(description="总数")


class AnalyticsDashboardResponse(BaseModel):
    """分析仪表板响应"""
    job_statistics: JobStatisticsResponse = Field(description="职位统计")
    top_companies: List[CategoryCount] = Field(description="热门公司")
    top_positions: List[CategoryCount] = Field(description="热门职位")
    city_distribution: List[CategoryCount] = Field(description="城市分布")
    industry_distribution: List[CategoryCount] = Field(description="行业分布")
    experience_distribution: List[CategoryCount] = Field(description="经验要求分布")