"""
従業員管理用のスキーマ定義 (Employee Schemas)
"""
from pydantic import BaseModel, EmailStr
from datetime import date, datetime
from typing import Optional
from decimal import Decimal


class DependentBase(BaseModel):
    """扶養家族の基本情報"""
    name: str
    relationship: str  # 配偶者/子/親/その他
    birth_date: Optional[date] = None
    mynumber: Optional[str] = None  # マイナンバーカード番号
    is_spouse: bool = False
    is_disabled: bool = False
    income_amount: Decimal = Decimal("0")
    valid_from: date
    valid_to: Optional[date] = None


class DependentCreate(DependentBase):
    """扶養家族の作成"""
    pass


class DependentUpdate(BaseModel):
    """扶養家族の更新"""
    name: Optional[str] = None
    relationship: Optional[str] = None
    birth_date: Optional[date] = None
    mynumber: Optional[str] = None
    is_spouse: Optional[bool] = None
    is_disabled: Optional[bool] = None
    income_amount: Optional[Decimal] = None
    valid_from: Optional[date] = None
    valid_to: Optional[date] = None


class Dependent(DependentBase):
    """扶養家族の情報"""
    dependent_id: int
    employee_id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class EmployeeBase(BaseModel):
    """従業員の基本情報"""
    employee_code: str
    name: str
    name_kana: Optional[str] = None
    birth_date: Optional[date] = None
    gender: Optional[str] = None
    my_number: Optional[str] = None
    email: Optional[EmailStr] = None
    phone: Optional[str] = None
    postal_code: Optional[str] = None
    address: Optional[str] = None
    hire_date: date
    termination_date: Optional[date] = None
    is_active: bool = True
    bank_name: Optional[str] = None
    bank_branch: Optional[str] = None
    bank_account_number: Optional[str] = None
    bank_account_type: Optional[str] = None  # 普通/当座
    notes: Optional[str] = None
    photo_url: Optional[str] = None
    my_number_card_image_url: Optional[str] = None
    residence_card_image_url: Optional[str] = None
    health_insurance_card_image_url: Optional[str] = None
    other_id_image_url: Optional[str] = None


class EmployeeCreate(EmployeeBase):
    """従業員の作成"""
    pass


class EmployeeUpdate(BaseModel):
    """従業員の更新"""
    employee_code: Optional[str] = None
    name: Optional[str] = None
    name_kana: Optional[str] = None
    birth_date: Optional[date] = None
    gender: Optional[str] = None
    my_number: Optional[str] = None
    email: Optional[EmailStr] = None
    phone: Optional[str] = None
    postal_code: Optional[str] = None
    address: Optional[str] = None
    hire_date: Optional[date] = None
    termination_date: Optional[date] = None
    is_active: Optional[bool] = None
    bank_name: Optional[str] = None
    bank_branch: Optional[str] = None
    bank_account_number: Optional[str] = None
    bank_account_type: Optional[str] = None
    notes: Optional[str] = None
    photo_url: Optional[str] = None
    my_number_card_image_url: Optional[str] = None
    residence_card_image_url: Optional[str] = None
    health_insurance_card_image_url: Optional[str] = None
    other_id_image_url: Optional[str] = None


class Employee(EmployeeBase):
    """従業員の情報"""
    employee_id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class EmployeeWithDependents(Employee):
    """扶養家族を含む従業員情報"""
    dependents: list[Dependent] = []
