from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, Field

from ...database.orm import SalaryConfigORM
from ...services.salary_config_service import SalaryConfigUpdate


class SalaryConfigRequest(BaseModel):
    """系统配置更新请求。"""

    config_name: str = Field(..., max_length=128)
    config_group: str = Field(..., max_length=64)
    config_value: str
    value_type: str = Field(default="string", max_length=32)
    is_enabled: bool = True
    remark: str = ""

    def to_update(self) -> SalaryConfigUpdate:
        return SalaryConfigUpdate(
            config_name=self.config_name,
            config_group=self.config_group,
            config_value=self.config_value,
            value_type=self.value_type,
            is_enabled=self.is_enabled,
            remark=self.remark,
        )


class SalaryConfigResponse(BaseModel):
    """系统配置响应。"""

    id: int
    config_key: str
    config_name: str
    config_group: str
    config_value: str
    value_type: str
    is_enabled: bool
    remark: str
    created_at: datetime
    updated_at: datetime

    @classmethod
    def from_orm_model(cls, config: SalaryConfigORM) -> "SalaryConfigResponse":
        return cls(
            id=config.id,
            config_key=config.config_key,
            config_name=config.config_name,
            config_group=config.config_group,
            config_value=config.config_value,
            value_type=config.value_type,
            is_enabled=config.is_enabled,
            remark=config.remark,
            created_at=config.created_at,
            updated_at=config.updated_at,
        )


class SalaryConfigDefaultsResponse(BaseModel):
    """默认配置初始化响应。"""

    created_count: int
    message: str
