# from app.modules.subscription.subscription_repository import subscriptionRepository


# class SubscriptionService:

#     def __init__(self):
#         self.repository = subscriptionRepository()

#     async def create_plan(self, subscription):
#         return await self.repository.create_plan(subscription)

#     async def get_all_plans(self):
#         return await self.repository.getAllPlan()

#     async def get_user_plan(self, user_id: str):
#         return await self.repository.getUserPlan(user_id)

#     async def update_plan(
#         self,
#         plan_id: str,
#         update_data: dict
#     ):
#         result = await self.repository.updatePlan(
#             plan_id,
#             update_data
#         )

#         if result.modified_count == 0:
#             raise Exception(
#                 "Plan not found or no changes made"
#             )

#         return True

#     async def delete_plan(
#         self,
#         plan_id: str
#     ):
#         result = await self.repository.soft_delete_plan(
#             plan_id
#         )

#         if result.modified_count == 0:
#             raise Exception(
#                 "Plan not found"
#             )

#         return True




from app.modules.subscription.subscription_repository import SubscriptionRepository
from app.modules.subscription.subscription_model import SubscriptionModel

class SubscriptionService:
    def __init__(self):
        self.repository = SubscriptionRepository()

    async def create_plan(self, subscription: SubscriptionModel):
        return await self.repository.create_plan(subscription)

    async def get_all_plans(self):
        return await self.repository.get_all_plans()

    async def get_plan_by_id(self, plan_id: str):
        return await self.repository.get_plan_by_id(plan_id)

    async def update_plan(self, plan_id: str, update_data: dict):
        result = await self.repository.update_plan(plan_id, update_data)
        if result.modified_count == 0:
            raise Exception("Plan not found or no changes made")
        return True

    async def delete_plan(self, plan_id: str):
        result = await self.repository.soft_delete_plan(plan_id)
        if result.modified_count == 0:
            raise Exception("Plan not found or already deleted")
        return True