from pydantic import Field
from datetime import datetime
from typing import Optional
from pydantic.networks import EmailStr
from src.apps.base.schemas.common import BaseSchema


# Shared properties
class PrincipalInfoBase(BaseSchema):
    first_name: Optional[str] = Field(description="First name of owner")
    last_name: Optional[str] = Field(description="Last name of owner")
    job_title: Optional[str] = Field(
        description="Job title of the principal (e.g. CEO, CFO, President, VP)"
    )
    phone: Optional[str] = Field(description="A valid phone number")
    email: Optional[EmailStr] = Field(description="A valid email")
    percent_owned: Optional[float] = Field(
        description="Percentage of ownership of the company."
    )
    ssn: Optional[str] = Field(
        description="Social Security Number (US) or Social Insurance Number (CA). Optional when business type is NPCORP, CHARITY, or GOV. Expected format: 9-digit string of numbers (e.g. '111444777'). Optional in CA."
    )
    dob: Optional[datetime] = Field(
        description="Date of birth of owner. A valid UNIX timestamp. Owner must be 18 years or older as of today."
    )
    city: Optional[str] = Field(description="City where address is located.")
    state: Optional[str] = Field(
        description="State/province/region of the address. For US and CA use 2-digit state/province codes (e.g. 'AL', 'AK', 'BC', 'ON', 'etc'.)"
    )
    country: Optional[str] = Field(description="2-digit Country code (e.g. 'US', 'CA')")
    address_line_1: Optional[str] = Field(
        description="First line of the street address"
    )
    address_line_2: Optional[str] = Field(
        description="Second line of the street address, if required."
    )
    nationality: Optional[str] = Field(description="Nationality of the owner")
    zipcode: Optional[str] = Field(
        description="Zip code or postal code of the address. No special characters."
    )
    is_management: Optional[bool] = Field(
        description="Indicates whether this principal is part of the management."
    )


class PrincipalInfoSchema(PrincipalInfoBase):
    id: int = Field(description="Id of Business Owner resource")


class PrincipalInfoCreateRequestSchema(PrincipalInfoBase):
    first_name: str = Field(description="First name of owner")
    last_name: str = Field(description="Last name of owner")
    job_title: str = Field(
        description="Job title of the principal (e.g. CEO, CFO, President, VP)"
    )
    dob: datetime = Field(
        description="Date of birth of owner. A valid UNIX timestamp. Owner must be 18 years or older as of today."
    )
    is_applicant: bool = Field(
        description="Indicates whether this owner is the applicant for the merchant account. For US merchant accounts (region = US) it is required that exactly one of the principals is specified as the applicant."
    )
    is_control_prong: bool = Field(
        description="This indicates whether the principal is the Control Prong. Control Prong is an individual with significant responsibility for managing the legal entity customer (e.g., a CEO, CFO, COO, Managing Member, General Partner, President, Vice-President, or Treasurer). For US merchant accounts (region = US) it is required that exactly one of the principals is specified as the Control Prong."
    )
    ssn: Optional[str] = Field(
        max_length=9,
        min_length=9,
        description="Social Security Number (US) or Social Insurance Number (CA). Optional when business type is NPCORP, CHARITY, or GOV. Expected format: 9-digit string of numbers (e.g. '111444777'). Optional in CA.",
    )


class PrincipalInfoUpdateRequestSchema(PrincipalInfoBase):
    ssn: Optional[str] = Field(
        max_length=9,
        min_length=9,
        description="Social Security Number (US) or Social Insurance Number (CA). Optional when business type is NPCORP, CHARITY, or GOV. Expected format: 9-digit string of numbers (e.g. '111444777'). Optional in CA.",
    )
