# coding: utf-8

"""
    LUSID API

    FINBOURNE Technology  # noqa: E501

    Contact: info@finbourne.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from datetime import datetime
from typing import Any, Dict, Optional, Union
from pydantic.v1 import Field, StrictFloat, StrictInt, StrictStr, constr, validator
from lusid.models.compounding import Compounding
from lusid.models.ex_dividend_configuration import ExDividendConfiguration
from lusid.models.flow_convention_name import FlowConventionName
from lusid.models.flow_conventions import FlowConventions
from lusid.models.index_convention import IndexConvention
from lusid.models.schedule import Schedule

class FloatSchedule(Schedule):
    """
    Schedule for fixed coupon payments  # noqa: E501
    """
    start_date: Optional[datetime] = Field(None, alias="startDate", description="Date to start generate from")
    maturity_date: Optional[datetime] = Field(None, alias="maturityDate", description="Date to generate to")
    flow_conventions: Optional[FlowConventions] = Field(None, alias="flowConventions")
    convention_name: Optional[FlowConventionName] = Field(None, alias="conventionName")
    ex_dividend_days: Optional[StrictInt] = Field(None, alias="exDividendDays", description="Optional. Number of calendar days in the ex-dividend period.  If the settlement date falls in the ex-dividend period then the coupon paid is zero and the accrued interest is negative.  If set, this must be a non-negative number.  If not set, or set to 0, then there is no ex-dividend period.                NOTE: This field is deprecated.  If you wish to set the ExDividendDays on a bond, please use the ExDividendConfiguration.")
    index_convention_name: Optional[FlowConventionName] = Field(None, alias="indexConventionName")
    index_conventions: Optional[IndexConvention] = Field(None, alias="indexConventions")
    notional: Optional[Union[StrictFloat, StrictInt]] = Field(None, description="Scaling factor, the quantity outstanding on which the rate will be paid.")
    payment_currency: StrictStr = Field(..., alias="paymentCurrency", description="Payment currency. This does not have to be the same as the nominal bond or observation/reset currency.")
    spread: Optional[Union[StrictFloat, StrictInt]] = Field(None, description="Spread over floating rate given as a fraction.")
    stub_type: Optional[StrictStr] = Field(None, alias="stubType", description="StubType required of the schedule    Supported string (enumeration) values are: [ShortFront, ShortBack, LongBack, LongFront, Both].")
    ex_dividend_configuration: Optional[ExDividendConfiguration] = Field(None, alias="exDividendConfiguration")
    compounding: Optional[Compounding] = None
    reset_convention: Optional[constr(strict=True, max_length=16, min_length=0)] = Field(None, alias="resetConvention", description="Control how resets are generated relative to payment convention(s).    Supported string (enumeration) values are: [InAdvance, InArrears].")
    schedule_type: StrictStr = Field(..., alias="scheduleType", description="The available values are: FixedSchedule, FloatSchedule, OptionalitySchedule, StepSchedule, Exercise, FxRateSchedule, FxLinkedNotionalSchedule, Invalid")
    additional_properties: Dict[str, Any] = {}
    __properties = ["scheduleType", "startDate", "maturityDate", "flowConventions", "conventionName", "exDividendDays", "indexConventionName", "indexConventions", "notional", "paymentCurrency", "spread", "stubType", "exDividendConfiguration", "compounding", "resetConvention"]

    @validator('schedule_type')
    def schedule_type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in ('FixedSchedule', 'FloatSchedule', 'OptionalitySchedule', 'StepSchedule', 'Exercise', 'FxRateSchedule', 'FxLinkedNotionalSchedule', 'Invalid'):
            raise ValueError("must be one of enum values ('FixedSchedule', 'FloatSchedule', 'OptionalitySchedule', 'StepSchedule', 'Exercise', 'FxRateSchedule', 'FxLinkedNotionalSchedule', 'Invalid')")
        return value

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> FloatSchedule:
        """Create an instance of FloatSchedule from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                            "additional_properties"
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of flow_conventions
        if self.flow_conventions:
            _dict['flowConventions'] = self.flow_conventions.to_dict()
        # override the default output from pydantic by calling `to_dict()` of convention_name
        if self.convention_name:
            _dict['conventionName'] = self.convention_name.to_dict()
        # override the default output from pydantic by calling `to_dict()` of index_convention_name
        if self.index_convention_name:
            _dict['indexConventionName'] = self.index_convention_name.to_dict()
        # override the default output from pydantic by calling `to_dict()` of index_conventions
        if self.index_conventions:
            _dict['indexConventions'] = self.index_conventions.to_dict()
        # override the default output from pydantic by calling `to_dict()` of ex_dividend_configuration
        if self.ex_dividend_configuration:
            _dict['exDividendConfiguration'] = self.ex_dividend_configuration.to_dict()
        # override the default output from pydantic by calling `to_dict()` of compounding
        if self.compounding:
            _dict['compounding'] = self.compounding.to_dict()
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        # set to None if ex_dividend_days (nullable) is None
        # and __fields_set__ contains the field
        if self.ex_dividend_days is None and "ex_dividend_days" in self.__fields_set__:
            _dict['exDividendDays'] = None

        # set to None if stub_type (nullable) is None
        # and __fields_set__ contains the field
        if self.stub_type is None and "stub_type" in self.__fields_set__:
            _dict['stubType'] = None

        # set to None if reset_convention (nullable) is None
        # and __fields_set__ contains the field
        if self.reset_convention is None and "reset_convention" in self.__fields_set__:
            _dict['resetConvention'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> FloatSchedule:
        """Create an instance of FloatSchedule from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return FloatSchedule.parse_obj(obj)

        _obj = FloatSchedule.parse_obj({
            "schedule_type": obj.get("scheduleType"),
            "start_date": obj.get("startDate"),
            "maturity_date": obj.get("maturityDate"),
            "flow_conventions": FlowConventions.from_dict(obj.get("flowConventions")) if obj.get("flowConventions") is not None else None,
            "convention_name": FlowConventionName.from_dict(obj.get("conventionName")) if obj.get("conventionName") is not None else None,
            "ex_dividend_days": obj.get("exDividendDays"),
            "index_convention_name": FlowConventionName.from_dict(obj.get("indexConventionName")) if obj.get("indexConventionName") is not None else None,
            "index_conventions": IndexConvention.from_dict(obj.get("indexConventions")) if obj.get("indexConventions") is not None else None,
            "notional": obj.get("notional"),
            "payment_currency": obj.get("paymentCurrency"),
            "spread": obj.get("spread"),
            "stub_type": obj.get("stubType"),
            "ex_dividend_configuration": ExDividendConfiguration.from_dict(obj.get("exDividendConfiguration")) if obj.get("exDividendConfiguration") is not None else None,
            "compounding": Compounding.from_dict(obj.get("compounding")) if obj.get("compounding") is not None else None,
            "reset_convention": obj.get("resetConvention")
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj
