from backend.models.models import MessageTemplateDoc class TemplateMessageService: async def get_template(self, template_id, tenant_id, region): return await MessageTemplateDoc.find_one({ "template_id": template_id, "tenant_id": tenant_id, "region": region, "is_active": True }) async def create_template(self, template:MessageTemplateDoc): return await template.create() async def update_template(self, id: str, tenant_id: str, data: dict): template = await MessageTemplateDoc.get(id) if not template or template.tenant_id != tenant_id: raise PermissionError("Forbidden") await template.set(data) return template async def delete_template(self, id: str, tenant_id: str): template = await MessageTemplateDoc.get(id) if not template or template.tenant_id != tenant_id: raise PermissionError("Forbidden") await template.delete() return {"success": True}