from typing import List
from app.api.brand_attribute_assessment import schema
from app.models.main.brand_attribute_assessment import BrandAttributeAssessmentBase, TblBrandAttributeAssessment
from app.utils.schemas_utils import CustomResponse
from sqlalchemy.orm import Session
from app.dependency.authantication import JWTPayloadSchema
from app.locale.messages import Messages
from fastapi import HTTPException

class BrandAttributeAssessmentService:
    def  __init__(self, db:Session, token:JWTPayloadSchema):
        self.db = db
        self.token = token
        
    async def create_brand(self, request:schema.BrandAttributeAssessmentCreate):
        created_brand = BrandAttributeAssessmentBase.model_validate(request.model_dump())
        TblBrandAttributeAssessment.create_brand_attribute_assessment(created_brand, self.db)
        self.db.commit()
        return CustomResponse(status="1", message=Messages.BRAND_ATTRIBUTE_ASSESSMENT)
    
    async def get_brand(self, group_id:int):
        new_get_brand = TblBrandAttributeAssessment.get_brand_attribute_assessment(group_id, self.db)
        if not new_get_brand:
            raise HTTPException(status_code=404, detail="Get group ID not found")
        return [schema.BrandAttributeAssessmentResponse.model_validate(get_group) for get_group in new_get_brand]
    
    async def update_brand(self, request:List[schema.BrandAttributeAssessmentUpdate]):
        for req in request:
            updated_brand = BrandAttributeAssessmentBase.model_validate(req.model_dump())
            if updated_brand.brand_id is None:
                return CustomResponse(status="-1", message=Messages.BRAND_ATTRIBUTE_ASSESSMENT_NOT)
            TblBrandAttributeAssessment.update_brand_attribute_assessment(updated_brand.brand_id, updated_brand, self.db)
        self.db.commit()
        return CustomResponse(status="1", message=Messages.BRAND_ATTRIBUTE_ASSESSMENT_UPDATE)
    
    async def delete_brand(self, group_id:List[int]):
        deleted_brand = TblBrandAttributeAssessment.delete_brand_attribute_assessment(group_id, self.db)
        if not deleted_brand:
            return CustomResponse(status="-1", message=Messages.BRAND_ATTRIBUTE_ASSESSMENT_NOT)
        return CustomResponse(status="1", message=Messages.BRAND_ATTRIBUTE_ASSESSMENT_DELETE)