from pydantic import BaseModel, EmailStr, Field
from typing import Optional, Dict
from datetime import date, datetime

# --- HR ---
class EmployeeBase(BaseModel):
    name: str
    email: EmailStr
    job_title: str
    department: str
    start_date: datetime
    termination_date: Optional[datetime]
    base_salary: float
    bonus: Optional[float]
    status: str
    location: Optional[str]
    extra_data: Optional[Dict] = {}

class EmployeeCreate(EmployeeBase):
    employee_id: str

class EmployeeUpdate(BaseModel):
    name: Optional[str]
    email: Optional[EmailStr]
    job_title: Optional[str]
    department: Optional[str]
    start_date: Optional[datetime]
    termination_date: Optional[datetime]
    base_salary: Optional[float]
    bonus: Optional[float]
    status: Optional[str]
    location: Optional[str]
    extra_data: Optional[Dict] = {}

# --- CRM ---
class OpportunityBase(BaseModel):
    customer_name: str
    contact_person: str
    email: EmailStr
    product: str
    deal_amount: float
    stage: str
    probability: float
    expected_close_date: datetime
    region: str
    extra_data: Optional[Dict] = {}

class OpportunityCreate(OpportunityBase):
    opportunity_id: str

class OpportunityUpdate(BaseModel):
    customer_name: Optional[str]
    contact_person: Optional[str]
    email: Optional[EmailStr]
    product: Optional[str]
    deal_amount: Optional[float]
    stage: Optional[str]
    probability: Optional[float]
    expected_close_date: Optional[datetime]
    region: Optional[str]
    extra_data: Optional[Dict] = {}
# HR schemas
class HRBase(BaseModel):
    employee_id: str
    name: str
    email: EmailStr
    job_title: str
    department: str
    start_date: Optional[datetime]
    termination_date: Optional[datetime]
    base_salary: float
    bonus: Optional[float] = None
    status: str
    location: Optional[str] = None
    class Config:
        orm_mode = True
        from_attributes = True
        json_encoders = {
            datetime: lambda v: v.strftime('%Y-%m-%d') if v else None
        }

class HRUpdate(BaseModel):
    name: Optional[str]
    email: Optional[EmailStr]
    job_title: Optional[str]
    department: Optional[str]
    start_date: Optional[str]
    termination_date: Optional[str]
    base_salary: Optional[float]
    bonus: Optional[float]
    status: Optional[str]
    location: Optional[str]

# CRM schemas
class CRMBase(BaseModel):
    opportunity_id: str
    customer_name: str
    contact_person: str
    email: EmailStr
    product: str
    deal_amount: float
    stage: str
    probability: float
    expected_close_date: Optional[date]
    region: Optional[str] = None
    class Config:
        orm_mode = True
        from_attributes = True
        json_encoders = {
            datetime: lambda v: v.strftime('%Y-%m-%d')
        }

class CRMUpdate(BaseModel):
    customer_name: Optional[str]
    contact_person: Optional[str]
    email: Optional[EmailStr]
    product: Optional[str]
    deal_amount: Optional[float]
    stage: Optional[str]
    probability: Optional[float]
    expected_close_date: Optional[str]
    region: Optional[str]



