from typing import Annotated, Any from anydi import Inject from fansifter_common.api.schemas import response_errors from fastapi import APIRouter, Path, status from ows_text_campaigns.api import auth, schemas from ows_text_campaigns.artist.exceptions import ( ArtistNotFoundError, ArtistSettingsNotFoundError, ArtistTwilioAccountError, InvalidArtistImageError, ) from ows_text_campaigns.artist.handlers import ( CreateArtistImageHandler, CreateArtistImageRequest, CreateArtistImageUploadCredentialsHandler, CreateArtistImageUploadCredentialsRequest, CreateOrUpdateArtistSettingsHandler, CreateOrUpdateArtistSettingsRequest, DeleteArtistImageHandler, DeleteArtistImageRequest, GetArtistSettingsByPhoneNumberHandler, GetArtistSettingsByPhoneNumberRequest, GetArtistSettingsHandler, GetArtistSettingsRequest, ScanArtistContentHandler, ScanArtistContentRequest, UpdateArtistSettingsHandler, UpdateArtistSettingsRequest, ) from ows_text_campaigns.assets.exceptions import ( AssetNotFoundError, InvalidContentTypeError, InvalidFileSizeError, InvalidImageSizeError, ) from ows_text_campaigns.rosters.exceptions import ArtistNotInRosterError router = APIRouter(tags=["Artist Settings"], prefix="/artist-settings") @router.get( "/by-phone-number/{phoneNumber}", operation_id="getArtistSettingsByPhoneNumber", response_model=schemas.ArtistSettingsByPhoneNumber, response_model_by_alias=True, responses=response_errors( ArtistSettingsNotFoundError, ), ) def get_artist_settings_by_phone_number( phone_number: Annotated[str, Path(alias="phoneNumber")], handler: Annotated[GetArtistSettingsByPhoneNumberHandler, Inject()], ) -> Any: return handler.handler( GetArtistSettingsByPhoneNumberRequest( phone_number=phone_number, ) ) @router.get( "/{globalParticipantId}", operation_id="getArtistSettings", response_model=schemas.ArtistSettings, response_model_by_alias=True, responses=response_errors( ArtistSettingsNotFoundError, ArtistNotInRosterError, ), ) def get_artist_settings( identity_id: auth.IdentityId, global_participant_id: Annotated[str, Path(alias="globalParticipantId")], handler: Annotated[GetArtistSettingsHandler, Inject()], ) -> Any: return handler.handler( GetArtistSettingsRequest( identity_id=identity_id, global_participant_id=global_participant_id, ) ) @router.post( "/{globalParticipantId}", operation_id="createOrUpdateArtistSettings", response_model=schemas.ArtistSettings, response_model_by_alias=True, responses=response_errors( ArtistNotFoundError, ArtistTwilioAccountError, InvalidContentTypeError, InvalidFileSizeError, InvalidImageSizeError, InvalidArtistImageError, ArtistNotInRosterError, ), ) def create_or_update_artist_settings( identity_id: auth.IdentityId, global_participant_id: Annotated[str, Path(alias="globalParticipantId")], data: schemas.CreateOrUpdateArtistSettingsInput, handler: Annotated[CreateOrUpdateArtistSettingsHandler, Inject()], ) -> Any: return handler.handle( CreateOrUpdateArtistSettingsRequest( identity_id=identity_id, global_participant_id=global_participant_id, artist_name=data.artist_name, welcome_message=data.welcome_message, opt_in_message=data.opt_in_message, phone_numbers=data.phone_numbers, twilio_account_sid=data.twilio_account_sid, twilio_auth_token=data.twilio_auth_token, twilio_messaging_service_sid=data.twilio_messaging_service_sid, refresh_api_key=data.refresh_api_key, ) ) @router.patch( "/{globalParticipantId}", operation_id="updateArtistSettings", response_model=schemas.ArtistSettings, response_model_by_alias=True, responses=response_errors( ArtistSettingsNotFoundError, AssetNotFoundError, ArtistNotInRosterError, ), ) def update_artist_settings( identity_id: auth.IdentityId, global_participant_id: Annotated[str, Path(alias="globalParticipantId")], data: schemas.UpdateArtistSettingsInput, handler: Annotated[UpdateArtistSettingsHandler, Inject()], ) -> Any: return handler.handle( UpdateArtistSettingsRequest( identity_id=identity_id, global_participant_id=global_participant_id, welcome_message=data.welcome_message, opt_in_message=data.opt_in_message, asset_id=data.asset_id, ) ) @router.post( "/{globalParticipantId}/image", operation_id="createArtistImage", response_model=schemas.Asset, response_model_by_alias=True, responses=response_errors( ArtistSettingsNotFoundError, InvalidContentTypeError, InvalidFileSizeError, InvalidImageSizeError, InvalidArtistImageError, ArtistNotInRosterError, ), status_code=status.HTTP_201_CREATED, ) def create_artist_image( identity_id: auth.IdentityId, global_participant_id: Annotated[str, Path(alias="globalParticipantId")], data: schemas.CreateArtistImageInput, handler: Annotated[CreateArtistImageHandler, Inject()], ) -> Any: return handler.handle( CreateArtistImageRequest( identity_id=identity_id, global_participant_id=global_participant_id, image_key=data.image_key, ) ) @router.delete( "/{globalParticipantId}/image", operation_id="deleteArtistImage", response_model=schemas.ArtistSettings, response_model_by_alias=True, responses=response_errors( ArtistSettingsNotFoundError, AssetNotFoundError, ArtistNotInRosterError, ), ) def delete_artist_image( identity_id: auth.IdentityId, global_participant_id: Annotated[str, Path(alias="globalParticipantId")], handler: Annotated[DeleteArtistImageHandler, Inject()], ) -> Any: return handler.handler( DeleteArtistImageRequest( identity_id=identity_id, global_participant_id=global_participant_id, ) ) @router.post( "/{globalParticipantId}/image/upload/credentials", operation_id="createArtistImageUploadCredentials", response_model=schemas.UploadCredentials, response_model_by_alias=True, responses=response_errors( ArtistSettingsNotFoundError, ArtistNotInRosterError, ), status_code=status.HTTP_201_CREATED, ) def create_artist_image_upload_credentials( identity_id: auth.IdentityId, global_participant_id: Annotated[str, Path(alias="globalParticipantId")], data: schemas.CreateArtistImageUploadCredentialsInput, handler: Annotated[CreateArtistImageUploadCredentialsHandler, Inject()], ) -> Any: return handler.handle( CreateArtistImageUploadCredentialsRequest( identity_id=identity_id, global_participant_id=global_participant_id, filename=data.filename, ) ) @router.post( "/{globalParticipantId}/content/scan", operation_id="scanArtistContent", response_model=schemas.ScanArtistContentOutput, response_model_by_alias=True, responses=response_errors( ArtistSettingsNotFoundError, ArtistNotInRosterError, ), ) def scan_artist_content( identity_id: auth.IdentityId, global_participant_id: Annotated[str, Path(alias="globalParticipantId")], data: schemas.ScanArtistContentInput, handler: Annotated[ScanArtistContentHandler, Inject()], ) -> Any: return handler.handle( ScanArtistContentRequest( identity_id=identity_id, global_participant_id=global_participant_id, opt_in_message=data.opt_in_message, welcome_message=data.welcome_message, ) )