"""V2 Vendor schema, update vendor.""" from marshmallow import Schema, ValidationError, fields, validate, validates_schema from marshmallow.validate import Length, OneOf from account.constants import constants class UpdateVendorSchema(Schema): """Update Vendor schema. NOTE: we will likely expand the schema of update-able properties as we increase usage of v2 update pattern. Properties: -vendor_id (int): Required. unique identifier of Vendor -contact_name (str): company name -name (str): name of vendor -company_brand_uuid (str): unique id for company brand. -service_tier_uuid (str): unique id for service tier. -label_identifier (enum): 'Frontline','Client Services','Catalog','D3','Film','TV','Test'. -label_summary (str): description of a label in AR. -owner (str): name of the owner.Required. -is_owned (enum): One of 'Yes', 'No'. -assigned_to_id (str): Stores the ID of the orchadmin user whom the label is assigned.Required. -assigned_reviewer_id (str | None): Foreign key to orchadmin_users table. Optional. -quarterback_label_manager_id (str | None): Foreign key to orchadmin_users table. Optional. -show_release_builder (enum): One of 'Y', 'N'. -priority (int): Initial priority number of the label.Required. -primary_genre_id (str): Genre id.Required. -estimated_total_products (int): number of total releases. -estimated_total_tracks (int): number of total tracks. -country_id (int): Foreign key to country table. Vendor's country. Required. -region (int | None): ID. Foreign key to region table. Optional. -website (str): Website URL of the label. -support_contact_email (str | None): Alternative email to use as the support contact.Optional. -contact_email (str): Contact email. -product_manager_id (str): ID of the product manager. -source (str): source of update -transfer_pricing_country (enum): ex. sme_argentina, orchard_gmbh, phonofile -wel_email_sender (int): oa user id of the welcome email sender -wel_email_send_date (datetime): datetime the welcome email was sent -sc_usa (str): SoundScan code for USA -sc_ca (str): SoundScan code for Canada """ vendor_id = fields.Integer(required=True) contact_name = fields.String(required=False) name = fields.String(required=False) company_brand_uuid = fields.String(required=False) service_tier_uuid = fields.Str(validate=OneOf(constants.SERVICE_TIER_UUIDS), required=False) label_identifier = fields.String(validate=OneOf(constants.LABEL_IDENTIFIER), required=False) label_summary = fields.String(required=False) owner = fields.String(required=False) is_owned = fields.Str(validate=OneOf(['Yes', 'No']), required=False) assigned_to_id = fields.Integer(required=False) assigned_reviewer_id = fields.Integer(required=False) quarterback_label_manager_id = fields.Integer(required=False, allow_none=True) show_release_builder = fields.String( validate=OneOf(constants.BOOLEAN_IDENTIFIER), required=False ) priority = fields.Integer(required=False) primary_genre_id = fields.Integer(required=False) estimated_total_products = fields.Integer(required=False) estimated_total_tracks = fields.Integer(required=False) country_id = fields.Integer(required=False) region = fields.Integer(required=False) website = fields.String(required=False) support_contact_email = fields.String(required=False) contact_email = fields.String(required=False) # Allowing null values here temporarily until we fix this field. # Updates to product_manager_id is currently broken. product_manager_id = fields.Integer(required=False, allow_none=True) source = fields.String(required=False) transfer_pricing_country = fields.Str( validate=OneOf(constants.TRANSFER_PRICING_COUNTRY), required=False ) wel_email_sender = fields.Integer(required=False) wel_email_send_date = fields.DateTime(required=False) sc_usa = fields.String(required=False, allow_none=True, validate=Length(max=4)) sc_ca = fields.String(required=False, allow_none=True, validate=Length(max=4)) class UpdateVendorExternalIdentifier1Schema(Schema): """Schema for updating external_identifier_1.""" vendor_uuid = fields.UUID(required=True) external_identifier_1 = fields.String(required=True) class UpdateVendorCountryIdSchema(Schema): """Schema for updating country.""" vendor_uuid = fields.UUID(required=True) country_id = fields.Integer(required=True) class UpdateVendorServiceTierSchema(Schema): """Schema for updating the service tier on a vendor.""" vendor_uuid = fields.UUID(required=True) service_tier_uuid = fields.Str( required=True, validate=OneOf(constants.SERVICE_TIER_UUIDS), ) class UpdateVendorInfoSchema(Schema): """Schema for updating vendor metadata (free-form, mostly nullable text columns). Every property is optional. Sending an explicit ``null`` clears the column on the vendor row (every column listed here is nullable in art_relations). Missing keys are left unchanged. ``load_default`` is intentionally absent so that "key omitted" stays distinguishable from "key sent as null" downstream. """ METADATA_FIELDS = ( 'name', 'owner', 'company', 'support_contact_email', 'label_identifier', 'contact_email', 'label_summary', 'relationship_notes', 'newsletter', 'website', 'priority', 'primary_genre', 'date_signed', 'status', ) vendor_uuid = fields.UUID(required=True) name = fields.String(required=False) owner = fields.String(required=False, allow_none=True) company = fields.String(required=False, allow_none=True) support_contact_email = fields.String(required=False, allow_none=True) label_identifier = fields.String( required=False, validate=OneOf(constants.LABEL_IDENTIFIER), ) contact_email = fields.String(required=False, allow_none=True) label_summary = fields.String(required=False, allow_none=True) relationship_notes = fields.String(required=False, allow_none=True) newsletter = fields.String( required=False, validate=OneOf(['Y', 'N']), ) website = fields.String(required=False, allow_none=True) priority = fields.Integer(required=False) primary_genre = fields.Integer(required=False) date_signed = fields.Date(required=False) status = fields.String(required=False, validate=OneOf(constants.VENDOR_STATUS)) @validates_schema def at_least_one_metadata_field(self, data, **_): if not any(f in data for f in self.METADATA_FIELDS): raise ValidationError( f'At least one of {", ".join(self.METADATA_FIELDS)} must be provided.' ) class UpdateVendorInternalStaffSchema(Schema): """Schema for updating internal staff assignments on a vendor. Each staff field is optional. Sending an explicit ``null`` clears the column where the DB allows it (assigned_to, assigned_reviewer, quarterback_label_manager, wel_email_sender). product_manager lives in a secondary table and cannot be unset via this endpoint. A missing key means "do not change". An explicit null means "set to NULL". To preserve that distinction, no ``load_default`` is set — missing keys stay missing on the deserialized output. """ vendor_uuid = fields.UUID(required=True) assigned_to = fields.Integer(required=False, allow_none=True) assigned_reviewer = fields.Integer(required=False, allow_none=True) quarterback_label_manager = fields.Integer(required=False, allow_none=True) wel_email_sender = fields.Integer(required=False, allow_none=True) product_manager = fields.Integer(required=False, allow_none=False) @validates_schema def at_least_one_staff_field(self, data, **_): if not any(f in data for f in constants.STAFF_FIELDS): raise ValidationError( f'At least one of {", ".join(constants.STAFF_FIELDS)} must be provided.' ) class UpdateVendorFirstStatementPeriodSchema(Schema): """Schema for validating first statement period request data. Properties: vendor_uuids (list[uuid]): - A required list of unique vendor identifiers. - Each ID must be an UUID. - There should be at least one UUID Example: {"first_statement_period": valid int} """ vendor_uuid = fields.UUID(required=True) first_statement_period = fields.Integer(required=True) class UpdateVendorNotesSchema(Schema): """Schema for validating POST /vendor//notes requests. This schema validates requests to update relationship notes for a vendor. Attributes: vendor_uuid (UUID): Required unique identifier for the vendor. relationship_notes (str): Required string containing the relationship notes. Example: { "relationship_notes": "These are some relationship notes." } """ vendor_uuid = fields.UUID(required=True) relationship_notes = fields.String(required=True) class UpdateVendorClosersSchema(Schema): """Schema for validating update vendor closers request data. Properties: closers (list[int]): - A required list of unique closer ids. - Each ID must be an Int. - There should be at least one ID. Example: {"closers": [1, 2]} """ vendor_uuid = fields.UUID(required=True) closers = fields.List( fields.Integer(), required=True, validate=validate.Length(min=1), )