def get(cls, token):
     try:
         target_audience_profile_id = decodeID(token)
         audience_profile = TargetAudienceProfileModel.find_by_id(
             target_audience_profile_id)
         if not audience_profile or audience_profile.token != token:
             return {"success": False, 'message': 'Record Not Found'}, 404
         return audience_profile.json(), 200
     except Exception as e:
         return {"success": False, "message": str(e)}
    def delete(cls, token):
        try:
            target_audience_profile_id = decodeID(token)
            audience_profile = TargetAudienceProfileModel.find_by_id(
                target_audience_profile_id)
            if not audience_profile or audience_profile.token != token:
                return {"success": False, 'message': 'Record Not Found'}, 404

            audience_profile.deleted_by = 1
            audience_profile.deleted_on = datetime.now()
            audience_profile.save_to_db()
            #audience_profile.delete_from_db()
            return {"success": True, 'message': 'Record deleted.'}, 200
        except Exception as e:
            return {"success": False, "message": str(e)}
    def put(self, token):
        try:
            data = self.parser.parse_args()
            validateObj = TargetAudienceProfileModel.validateData(
                data, request)
            if type(validateObj) is dict:
                return {"success": False, "errors": validateObj}, 400

            target_audience_profile_id = decodeID(token)
            audience_profile = TargetAudienceProfileModel.find_by_id(
                target_audience_profile_id)
            if not audience_profile or audience_profile.token != token:
                return {"success": False, 'message': 'Record Not Found'}, 404

            audience_profile.audience_profile_name = data[
                'audience_profile_name']
            audience_profile.business = data['business']
            audience_profile.age_group_id = data['age_group_id']
            audience_profile.gender_id = data['gender_id']
            audience_profile.target_languages = data['target_languages']
            audience_profile.target_nationality = data['target_nationality']
            audience_profile.target_education = data['target_education']
            audience_profile.target_occupation = data['target_occupation']
            audience_profile.target_interest = data['target_interest']
            audience_profile.modified_on = datetime.now()
            audience_profile.modified_by = 1
            name = data['audience_profile_name']
            if name.strip():
                audience_profile.save_to_db()
            else:
                return {
                    "success": False,
                    "message": "String Should not be empty"
                }

            return {
                "success": True,
                "message": "Record updated successfully."
            }, 200
        except Exception as e:
            return {"success": False, "message": str(e)}