"""Pydantic Model For Report Custom.""" # pylint: disable=E0213 from datetime import datetime from pydantic import BaseModel from pydantic import ConfigDict from pydantic import field_validator from moneyhub.constants.constants import NumberFormat from moneyhub.constants.constants import ReportCustomColumnDimension from moneyhub.constants.constants import ReportCustomFileType from moneyhub.constants.constants import ReportCustomRowDimension from moneyhub.constants.constants import ReportCustomStatus from moneyhub.constants.constants import RevenueDisplayType from moneyhub.constants.constants import RevenueType class ReportCustomFiltersSchema(BaseModel): """Custom report filters.""" activity_period_ids: list[int] = [] artist_ids: list[int] = [] country_codes: list[str] = [] imprint_ids: list[int] = [] product_ids: list[int] = [] project_ids: list[int] = [] store_ids: list[int] = [] subaccount_ids: list[int] = [] recording_ids: list[str] = [] track_unique_ids: list[int] = [] transaction_type_ids: list[int] = [] @field_validator('*', mode='before') @classmethod def enforce_unique_ids(cls, values: list) -> list: """Enforce unique ids for each filter. Args: values (list): values to be filtered Returns: list: a list of de-duplicated values """ return list(dict.fromkeys(values)) class ReportCustomCreateSchema(BaseModel): """Custom report create request body.""" contract_id: int | None = None subaccount_id: int | None = None statement_period_ids: list[int] revenue_type: RevenueType revenue_display_type: RevenueDisplayType = RevenueDisplayType.NET dimension_column: ReportCustomColumnDimension dimension_row: ReportCustomRowDimension number_format: NumberFormat = NumberFormat.US file_type: ReportCustomFileType = ReportCustomFileType.CSV filters: ReportCustomFiltersSchema | None = None class ReportCustomDetailSchema(ReportCustomCreateSchema, BaseModel): """Custom report detail response.""" report_custom_id: int account_id: int report_custom_status: ReportCustomStatus file_location: str | None = None created_at: datetime created_by: str model_config = ConfigDict(from_attributes=True) @field_validator('statement_period_ids', mode='before') @classmethod def convert_string_to_list(cls, statement_periods: str | list) -> list[int]: """Convert a value into a list of integers. Args: statement_periods (str): value to be converted to a string Returns: list: a list of statement periods converted to ints """ if isinstance(statement_periods, str): if not statement_periods: return [] return [int(period) for period in statement_periods.split(',')] return statement_periods class ReportCustomUpdateSchema(BaseModel): """Custom report update request body.""" file_location: str | None = None report_custom_status: ReportCustomStatus