"""Schema for product-tracks.""" from marshmallow import fields from analytics.schemas import fields as custom_fields from analytics.schemas.common import ( BaseSchema, SourceSchema, StoreItemSchema, StreamBreakdownItemSchema, StreamDataSchema, ) class ProductMetricSchema(BaseSchema): """Marshmallow schema for the metrics in a list of product metrics.""" product_id = fields.Integer() upc = fields.String() streams_1_day = fields.Integer() growth_percentage_1_day = fields.Float(data_key="growth_percentage_1_day") streams_7_days = fields.Integer() growth_percentage_7_days = fields.Float(data_key="growth_percentage_7_days") streams_28_days = fields.Integer() growth_percentage_28_days = fields.Float(data_key="growth_percentage_28_days") streams_all_time = fields.Integer() release_date = custom_fields.UnifiedDate() sale_start_date = custom_fields.UnifiedDate() class ProductMetricsSchema(BaseSchema): """Marshmallow schema for the list of product metrics.""" metrics = fields.Nested(nested=ProductMetricSchema, many=True) total_products = fields.Integer() class StreamsAggregateSchema(BaseSchema): """Marshmallow schema for streams.aggregate.""" aggregate = fields.Nested(StreamDataSchema) items = fields.Nested(StreamBreakdownItemSchema, many=True) stores = fields.Nested(StoreItemSchema, many=True) class ProductTrackItemSchema(BaseSchema): """Marshmallow schema for product tracks.""" track_id = fields.Integer(data_key="track_id") isrc = fields.String() streams = fields.Nested(StreamsAggregateSchema) class ProductSchema(BaseSchema): """Marshmallow schema for product.""" product_id = fields.String(data_key="product_id") streams = fields.Nested(StreamsAggregateSchema) tracks = fields.Nested(ProductTrackItemSchema, many=True) sources = fields.Nested(SourceSchema, many=True) class ProductAggregateStreamsSchema(BaseSchema): """Marshmallow schema for product aggregate streams.""" product_id = fields.String() streams_all_time = fields.Integer() growth_percentage_7_days = fields.Float(allow_none=True)