from sqlalchemy.orm import Session
from app.infrastructure.database.models.federal_districts import FederalDistrict

class FederalDistrictsRepository:
    def __init__(self, db: Session):
        self.db = db

    def get_all(self):
        return self.db.query(FederalDistrict).all()

    def get_by_id(self, federal_district_id: int):
        return self.db.query(FederalDistrict).filter(FederalDistrict.id == federal_district_id).first()

    def create(self, federal_district: FederalDistrict):
        self.db.add(federal_district)
        self.db.commit()
        self.db.refresh(federal_district)
        return federal_district

    def update(self, federal_district: FederalDistrict):
        self.db.commit()
        return federal_district

    def delete(self, federal_district_id: int):
        federal_district = self.db.query(FederalDistrict).filter(FederalDistrict.id == federal_district_id).first()
        if federal_district:
            self.db.delete(federal_district)
            self.db.commit()
            return federal_district
        return None
