"""Logic for Validating bit depth.""" from assets.constants import error from assets.exceptions import ( BitsPerSampleNotFound, DesiredBitsPerSampleNotFound, ) from assets.models import asset_final, ows_product def _is_desired_bit_depth_found(product_id: int, desired_bit_depth: int) -> None: """Check for desired bit depth value. Args: product_id (int): Unique identification for product. desired_bit_depth(int): Desired bit depth value to match with. """ bit_depths_list = asset_final.get_bit_depths_for_products(product_id) # Validating tracks with null bit depths. if len(bit_depths_list) == 1 and bit_depths_list[0] is None: raise BitsPerSampleNotFound(error.NO_BITS_PER_SAMPLE_FOUND) if len(bit_depths_list) != 1 or int(bit_depths_list[0]) != int(desired_bit_depth): raise DesiredBitsPerSampleNotFound(error.DESIRED_BIT_DEPTH_NOT_FOUND) def check_for_desired_bit_depth(product_id: int, desired_bit_depth: int) -> None: """Check for desired bit depth for provided product. Args: product_id (int): Unique identification for product. desired_bit_depth (int): Desired bit depth to match. Returns: Response: Bit depth validation messages for assets if any. """ ows_product.get_product_by_id(product_id) # Validate bit depth values for all assets. _is_desired_bit_depth_found(product_id, desired_bit_depth)