# 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 typing import List, Dict, Optional, Any, Union, TYPE_CHECKING
from typing_extensions import Annotated
from pydantic.v1 import BaseModel, StrictStr, StrictInt, StrictBool, StrictFloat, StrictBytes, Field, validator, ValidationError, conlist, constr
from datetime import datetime
from lusid.models.model_property import ModelProperty
from lusid.models.simple_rounding_convention import SimpleRoundingConvention
from lusid.models.time_zone_conventions import TimeZoneConventions
from lusid.models.trading_conventions import TradingConventions

class ShareClass(BaseModel):
    """
    ShareClass
    """
    instrument_identifiers: Dict[str, Optional[StrictStr]] = Field(description="Unique instrument identifiers", alias="instrumentIdentifiers")
    code:  StrictStr = Field(...,alias="code", description="The unique code for the Share Class. Must be unique within the Fund.") 
    name:  StrictStr = Field(...,alias="name", description="The display name of the Share Class.") 
    description:  Optional[StrictStr] = Field(None,alias="description", description="An optional description for the Share Class.") 
    share_class_short_code:  StrictStr = Field(...,alias="shareClassShortCode", description="A short code that uniquely identifies the share class within the Fund.") 
    launch_price: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The launch price set when a shareclass is added to the fund. Defaults to 1.", alias="launchPrice")
    launch_date: Optional[datetime] = Field(default=None, description="The launch date set when a shareclass is added to the fund. Defaults to Fund Inception Date.", alias="launchDate")
    apportionment_factor: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The weighting factor used for apportionment across this share class.", alias="apportionmentFactor")
    properties: Optional[Dict[str, ModelProperty]] = Field(default=None, description="An optional set of properties to attach to the auto-created Instrument. Only applied when createInstrument is true.")
    fund_share_class_type:  StrictStr = Field(...,alias="fundShareClassType", description="The Type of Share Class. Supported values are: Unitised / Non-Unitised / Series / Private Equity / Partnership.") 
    distribution_type:  StrictStr = Field(...,alias="distributionType", description="The type of distribution the ShareClass will calculate. Supported values are: Income, Accumulation.") 
    dom_ccy:  StrictStr = Field(...,alias="domCcy", description="The domestic currency of the ShareClass instrument.") 
    trading_conventions: Optional[TradingConventions] = Field(default=None, alias="tradingConventions")
    units_precision: Optional[StrictInt] = Field(default=None, description="Decimal places for the share class units.", alias="unitsPrecision")
    price_precision: Optional[StrictInt] = Field(default=None, description="Decimal places for the share class price.", alias="pricePrecision")
    rounding_conventions: Optional[List[SimpleRoundingConvention]] = Field(default=None, description="Rounding conventions used for the ShareClass quotes.", alias="roundingConventions")
    rounding_conventions_units: Optional[List[SimpleRoundingConvention]] = Field(default=None, description="Rounding conventions used for the ShareClass units.", alias="roundingConventionsUnits")
    time_zone_conventions: Optional[TimeZoneConventions] = Field(default=None, alias="timeZoneConventions")
    distribution_payment_type:  Optional[StrictStr] = Field(None,alias="distributionPaymentType", description="The tax treatment applied to distributions. Supported values are: Gross, Net.") 
    hedging:  StrictStr = Field(...,alias="hedging", description="Indicates whether the ShareClass applies currency hedging. Supported values are: Invalid, None, ApplyHedging.") 
    __properties = ["instrumentIdentifiers", "code", "name", "description", "shareClassShortCode", "launchPrice", "launchDate", "apportionmentFactor", "properties", "fundShareClassType", "distributionType", "domCcy", "tradingConventions", "unitsPrecision", "pricePrecision", "roundingConventions", "roundingConventionsUnits", "timeZoneConventions", "distributionPaymentType", "hedging"]

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

    def __str__(self):
        """For `print` and `pprint`"""
        return pprint.pformat(self.dict(by_alias=False))

    def __repr__(self):
        """For `print` and `pprint`"""
        return self.to_str()

    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) -> ShareClass:
        """Create an instance of ShareClass 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={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of each value in properties (dict)
        _field_dict = {}
        if self.properties:
            for _key in self.properties:
                if self.properties[_key]:
                    _field_dict[_key] = self.properties[_key].to_dict()
            _dict['properties'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of trading_conventions
        if self.trading_conventions:
            _dict['tradingConventions'] = self.trading_conventions.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in rounding_conventions (list)
        _items = []
        if self.rounding_conventions:
            for _item in self.rounding_conventions:
                if _item:
                    _items.append(_item.to_dict())
            _dict['roundingConventions'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in rounding_conventions_units (list)
        _items = []
        if self.rounding_conventions_units:
            for _item in self.rounding_conventions_units:
                if _item:
                    _items.append(_item.to_dict())
            _dict['roundingConventionsUnits'] = _items
        # override the default output from pydantic by calling `to_dict()` of time_zone_conventions
        if self.time_zone_conventions:
            _dict['timeZoneConventions'] = self.time_zone_conventions.to_dict()
        # set to None if description (nullable) is None
        # and __fields_set__ contains the field
        if self.description is None and "description" in self.__fields_set__:
            _dict['description'] = None

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = ShareClass.parse_obj({
            "instrument_identifiers": obj.get("instrumentIdentifiers"),
            "code": obj.get("code"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "share_class_short_code": obj.get("shareClassShortCode"),
            "launch_price": obj.get("launchPrice"),
            "launch_date": obj.get("launchDate"),
            "apportionment_factor": obj.get("apportionmentFactor"),
            "properties": dict(
                (_k, ModelProperty.from_dict(_v))
                for _k, _v in obj.get("properties").items()
            )
            if obj.get("properties") is not None
            else None,
            "fund_share_class_type": obj.get("fundShareClassType"),
            "distribution_type": obj.get("distributionType"),
            "dom_ccy": obj.get("domCcy"),
            "trading_conventions": TradingConventions.from_dict(obj.get("tradingConventions")) if obj.get("tradingConventions") is not None else None,
            "units_precision": obj.get("unitsPrecision"),
            "price_precision": obj.get("pricePrecision"),
            "rounding_conventions": [SimpleRoundingConvention.from_dict(_item) for _item in obj.get("roundingConventions")] if obj.get("roundingConventions") is not None else None,
            "rounding_conventions_units": [SimpleRoundingConvention.from_dict(_item) for _item in obj.get("roundingConventionsUnits")] if obj.get("roundingConventionsUnits") is not None else None,
            "time_zone_conventions": TimeZoneConventions.from_dict(obj.get("timeZoneConventions")) if obj.get("timeZoneConventions") is not None else None,
            "distribution_payment_type": obj.get("distributionPaymentType"),
            "hedging": obj.get("hedging")
        })
        return _obj

ShareClass.update_forward_refs()
